Algum amigo pode me ajudar em JS?

6 respostas
B

Amigos estou apanhando em um JS aqui.
Seguinte : criei uma imagem, quero clicar nesta imagem e, através de um JS, ele colorir um TD.

Acontece que, ao clicar nesta imagem, o form esta sendo SUBMITADO !!!

Num sei o que pode ser !

Meu JSP :

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="/WEB-INF/tld/fmt.tld"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Cadastro de Associados</title>
<link href="<c:url value="/css/estilo.css"/>" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
body {
	background-color: #FFFFEA;
}
-->
</style>
<script type="text/javascript">
	function mostrar(acao){
		if (acao=='comercial'){
			document.getElementById('comercio').style.bgcolor="#FBF8B7";
			}
	}
	function enviar(acao){
		document.forms[0].acao.value = acao;
		if (document.forms[0].acao.value=='pesquisar'){
			document.forms[0].submit();
			}
		else {
			if (verifica()){
				document.forms[0].submit();
				}
			else{ 
				return false;
			}
		}
	}
	function verifica(){
		if(document.forms[0].descricao.value==""){ 
			alert("O Campo \"Descrição\" está em branco!"); 
			return false; 
		}
		if((document.forms[0].id.value=="") && (document.forms[0].acao.value == 'excluir')){
			alert("Sem dados para Excluir!");
			return false;
		}		
		return true;	
	} 

</script>    

</head>
<body>
<form name="cadFuncao" action ="${pageContext.request.contextPath}/SocioSL" method="post">
	<input type="hidden" name="acao">
    <table width="100%" border="0">	    
    <tr>      
      <td colspan=2 class="style3bold" align="center">Função</td>
    </tr>
    </table>
  <table width="100%">
  	<tr>
		<td width="25%"></td>
		<td width="10%" bgcolor="#FBF8B7" align="center">
			<input type="image" src="${pageContext.request.contextPath}/images/comercial32.gif" onClick="mostrar('comercial')"> </td>  		
		<td width="25%"></td>
  	</tr>
  	<tr>
		<td width="25%"></td>
		<td id="comercio" width="10%" align="center" class="stylesmall">Comerciais</td>  		
		<td width="25%"></td>
  	</tr>
	<tr>
	  	<td width="100%" height="20" colspan="3">
	</tr>	
  </table>
   <table width="100%">
	  <tr>
          <td width="42%" ></td>		  
          <td width="5%" align=center><input name="button" type="button" class="style3bold" onClick="return enviar('excluir')" value="Excluir"></td>
          <td width="5%" align=center><input name="button" type="button" class="style3bold" onClick="return enviar('salvar')" value="Salvar"></td>
          <td width="43%" ></td>
      </tr>
  </table>
    <c:if test="${msgRequest!=null}">
   	<script>
       alert('${msgRequest}')
	</script>
   </c:if>    	 
</form>
</body>
</html>

Alguem pode me dar uma luz ?

ab

Bob

6 Respostas

Rage

Vc ja tentou ‘alertar’ a sua acao pra ver qual ta chegando la?
Tenta tb alertar qq outra coisa dentro da função pra ver se está chegando corretamente.
Vc esta chamando a função certa na img, mas como vc nao esta usando img src e sim input type=nutton, creio q vc tenha que fechar esse button com …tenta la…
[]´s

cristianomariano

Tenta usar <img> ao invés de &lt;input type="image"&gt;
Abraço!

rogeriuslima

cristianomariano:
Tenta usar <img> ao invés de &lt;input type="image"&gt;
Abraço!

O nosso colega Rage tá certo, antes de mais nada ponha em alguns trechos do seu código um alert para vc ver o valor da variavel que tá chegando.
E também siga a sugestão do cristianomariano e substitua a tag, lembrando que o fechamento destas tag’s é utilizando o “/” antes do “>” da tag
o mesmo vale para os inputs.
Abraços.

B

Vou tentar aqui e falo com vcs gurinha

abs

Bob

B

Tá quase ! hehehe

Amigos, Troquei a tag vejam :

<table width="100%">
  	<tr>
		<td width="25%"></td>
		<td width="10%" bgcolor="#FBF8B7" align="center">
		  <a href="#"> <img src="${pageContext.request.contextPath}/images/comercial32.gif" border="0" onclick="mostrar('comercial')"></a> </td>  		
		<td width="25%"></td>
  	</tr>
  	<tr>
		<td width="25%"></td>
		<td id="comercio" width="10%" align="center" class="stylesmall">Comerciais</td>  		
		<td width="25%"></td>
  	</tr>
	<tr>
	  	<td width="100%" height="20" colspan="3">
	</tr>	
  </table>

Meu JS :

function mostrar(acao){
		if (acao=='comercial'){
			alert('passei');
			document.getElementById('comercio').style.bgcolor="#FBF8B7";
			}
	}

Agora ele não submita mas …

Ele não tá colorindo o TD comercio com o bgcolor :cry:

Mais alguma coisa que estou errando ?

abs

Bob

B

Amigos, consegui resolver vejam :

function mudarCor(celulaMudar){
		celula = document.getElementById(celulaMudar);
		celula.style.backgroundColor="#FBF8B7";
		
	}

Esta funcao coloquei dentro do JSP
Agora estou tentando fazer uma genérica lá no arquivo .JS mas ele não está identificando o Form corretamente

Conseguindo falo com vcs

abs
Muito Obrigado

Bob

Criado 10 de março de 2008
Ultima resposta 11 de mar. de 2008
Respostas 6
Participantes 4