Bloquear submit

8 respostas
Z

Pessoal estou com um problemão… Em todas as minhas páginas quando eu dou um enter em algum campo ele submete a minha página e consequentemente é gerado um erro.

Eu consigo bloquear isso ?

A solução que eu conheço é colocar no onsubmit uma função de validação, mas eu teria um retrabalho imenso…

Valeu…
[]'s

8 Respostas

R

Como é que está seu código HTML?

A

Bom dia zezinho,

Imagino que se vc usa-se a tecla TAB ao inves de enter seria melhor do que ficar apertando o ENTER. Mas tb tem outro lado que se vc deve estar preenchendo alguma coisa, um formulario ou coisa do tipo, certo ? E esse formulario terá validações, nem que elas sejam em JS, certo ? pois bem, se por acaso vc errasse e apertasse o enter, cairia na validação e seu problema diminuiria. Esse é so uma ideia.

falo
Abs

S

O jeito mais rapido eu acho que seria através do javascript tb!!

quando todos os campos estivessem preenchidos voce poderia preencher o action do form,

agora não sou expert!!eheheh só tentei ajudar;…r

R

Isso acontece por que cada componente está em um form específico, talvez vc esteja usando o Dreamweaver que faz isso automaticamente. Coloque todos dentro de um form só, assim:

<body>
<form name="form1" method="post" action="">  <--- AQUI
  <table width="344" height="161" border="1">
    <tr>
      <td>
        <input type="text" name="textfield">  
        <input type="text" name="textfield">
        <input type="text" name="textfield">
      </td>
    </tr>
  </table>
</form>                                                          <--- AQUI
</body>

Mas vc não usará ENTER pra passar de um componente p outro, tem que usar TAB.

Z

rodrigus:
Isso acontece por que cada componente está em um form específico, talvez vc esteja usando o Dreamweaver que faz isso automaticamente. Coloque todos dentro de um form só, assim:

<body>
<form name="form1" method="post" action="">  <--- AQUI
  <table width="344" height="161" border="1">
    <tr>
      <td>
        <input type="text" name="textfield">  
        <input type="text" name="textfield">
        <input type="text" name="textfield">
      </td>
    </tr>
  </table>
</form>                                                          <--- AQUI
</body>

Mas vc não usará ENTER pra passar de um componente p outro, tem que usar TAB.

Não estou usando o Dreamweaver, todos meus campos estão no meu formBean, o problema que eu não quero usar o enter ou o tab para mudar de campo, o que ouve foi um acidente, apertei o enter por acaso quando eu estava preenchendo um campo, pelo que eu estou vendo terei que fazer uma validação no onsubmit… será que só tem essa saída ?

R

é bem possível então.

Z

O pior que nesta jsp não tenho o problema..Quando eu clico em qualquer campo não ocorre nada..somente com o click do botão

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
 <html:base/>
<html:html>
<head>
<title>..</title>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<LINK rel="stylesheet" type="text/css" href="/componentes/estilosApp.css">
<LINK rel="stylesheet" type="text/css" href="/veic/componentes/veic_style.css">
<SCRIPT language="JavaScript" src="/veic/componentes/veic_scripts.js"></SCRIPT>
<SCRIPT language="JavaScript">

	function Alterar(){
		if (document.getElementById('codigoParametro').value.length == 0){
			alert("Selecione um banco.")
		}else {
			document.manterBancoForm.action = '../../../manterBancoAction.do?parAcao=recuperar'; 
			document.manterBancoForm.submit();
		}	
	}		
	function Incluir(){
		document.manterBancoForm.action = "../../../manterBancoAction.do?parAcao=carregarInclusao";
		document.manterBancoForm.submit();	
	}
	
	function Excluir()	{
		if (document.getElementById('codigoParametro').value.length == 0){
			alert("Selecione um banco.")
		}else if(confirm("Tem certeza que deseja excluir este banco ?")){
			document.manterBancoForm.action = '../../../manterBancoAction.do?parAcao=excluir'; 
			document.manterBancoForm.submit();
		}		
	}
	function Pesquisar(){
		divListaItens.style.display = "";
		document.manterBancoForm.action = '../../../manterBancoAction.do?parAcao=pesquisarPorParam'; 
		document.manterBancoForm.submit();
	}
	function setaValor(valor){
		document.getElementById('codigoParametro').value = valor;		
	}
</SCRIPT>
</head>
<BODY class="fnd1">
<html:form action="/manterBancoAction">
  <input type="hidden" name="codigoParametro">
  
  <logic:messagesPresent name="message">
      <html:messages id="message" message="true">
          <bean:write name="messages" />
      </html:messages>
  </logic:messagesPresent>

   
	<!-- ####### Tabela de Alinhamento ####### -->
	<TABLE border="0" cellpadding="0" cellspacing="0" width="748">
		<TR>
			<TD colspan="2" height="5"></TD>
		</TR>
		<TR>
			<TD width="21"></TD>
			<TD>
				<!-- ####### Titulo ####### -->
				<DIV id="divTitulo" style="width:100%">
					<p>
						<FONT class="ttl2">Manuten&ccedil;&atilde;o</FONT><BR>
						<FONT class="ttl1">Manter Banco</FONT>
					</p>
				</DIV>
				<!-- ####### Pesquisa ####### -->

				<DIV id="divPesquisa" style="width:100%;padding-top:10px;">
					<TABLE border="1" borderColor="#990000" borderColorDark="white" cellpadding="3" cellspacing="0" rules="rows" frame="below" class="tab1" width="100%">
						<TR align="center">
							<TD colspan='6' class='ttltab1'>Op&ccedil;&otilde;es de Pesquisa</TD>
						</TR>
						<TR>			
							<TD width="80" class="lbl1"><b>Cód. Banco:</b> </TD>
							<TD><html:text property="codigo" size="15" onkeypress="onlyNum()" styleClass="txt1" /></TD>
							<TD width="85" class="lbl1"><b>Nome Banco:</b></TD>
							<TD><html:text property="nome" styleClass="txt1" /></TD>
							<TD width="60" class='txt1'><b>Situação:</b></TD>
							<TD>
								<html:select property="ativo" styleClass="frmCmb1">
									<html:option value="T">Todos</html:option>
									<html:option value="A">Ativo</html:option>
									<html:option value="I">Inativo</html:option>
								</html:select>
							</TD>
						</TR>
						
					</TABLE>
				</DIV>
				<!-- ####### LISTA DE ITENS ####### -->

			       <!-- <IFRAME src="pesq_bancoGrade.jsp" height="180" width="100%" scrolling="auto" frameborder=0 name="frameDados" id="frameDados"></IFRAME>					 -->
				<DIV id="divListaItens" style="width:100%;display: none">

				<TABLE border="1" borderColor="#990000" borderColorDark="white" cellpadding="3" cellspacing="0" rules="rows" frame="below" class="tab1" width="100%">
					<TR align="center">
						<TD colspan="7" class="ttlTab1">Bancos</TD>
					</TR>
					<TR align="center">
						<TD width="20" class="ttlTab2">&nbsp;</TD>
						<TD width="80" class="ttlTab2"><B>Cód. Banco</B></TD>
						<TD width="300" class="ttlTab2" align="left"><B>Nome Banco</B></TD>
						<TD width="100" class="ttlTab2"><B>Sigla</B></TD>
						<TD width="100" class="ttlTab2"><B>Agrupado</B></TD>
						<TD class="ttlTab2"><B>Situação</B></TD>
						<TD width="10" class="ttlTab2">&nbsp;</TD>
					</TR>
				</TABLE>
				<DIV id="divScroll" style="height:140px">	
						
					<TABLE border="1" borderColor="#990000" borderColorDark="white" cellpadding="3" cellspacing="0" rules="rows" frame="below" class="tab1" width="100%">
							
						<logic:present name="listaBanco">
							<logic:iterate name="listaBanco" id="lista">
								<TR align="center">
									<TD width="20" class="txtTab1"><input type="radio" name="itemSelecao" id="<bean:write property="codigo" name="lista"/>" value="radiobutton" class="frmTxt1" onclick="setaValor('<bean:write property="codigo" name="lista"/>')"></TD>
									<TD width="80" class="txtTab1"><bean:write property="codigo" name="lista"/></TD>
									<TD width="300" class="txtTab1" align="left"><bean:write property="nome" name="lista"/></TD>
									<TD width="100" class="txtTab1"><bean:write property="sigla" name="lista"/></TD>
									<TD width="100" class="txtTab1"><bean:write property="agrupado" name="lista"/></TD>
									<TD class="txtTab1"><bean:write property="ativo" name="lista"/></TD>
							</TR>
						</logic:iterate>
					</logic:present>
						
					</TABLE>
				</DIV>
			</DIV>
			<!-- ####### BOTOES ####### -->
			<DIV id="divBotoes">
				<DIV id="botaoIncluir"><INPUT type="Button" id="btoIncluir" name="btoIncluir" value="incluir" class="bto1" onclick="Incluir()"></DIV>
				<DIV id="botaoAlterar" style="display:none"><INPUT type="Button" id='btoAlterar' name='btoAlterar' value="alterar" class="bto1" onclick="Alterar()"></DIV>
				<DIV id="botaoExcluir" style="display:none"><INPUT type="Button" id='btoExcluir' name='btoExcluir' value="excluir" class="bto1" onclick="Excluir()"></DIV>
				<DIV id="botaoPesquisar"><INPUT type=button class=bto1 Value='pesquisar' id='bt_pesquisar' name='bt_pesquisar' align='left' onClick='Pesquisar()'></DIV>
			</DIV>
		</TD>
	</TR>
	<logic:present name="lista">
		<logic:notEmpty name="lista">
			<script>
				divListaItens.style.display = "";
				document.getElementById("botaoExcluir").style.display = "";
				document.getElementById("botaoAlterar").style.display = "";
			</script>
		</logic:notEmpty>
	</logic:present>

  
  <logic:notPresent name="lista">
  	<logic:empty name="lista">
  		<script>
	  		divListaItens.style.display = "none";
			document.getElementById("botaoExcluir").style.display = "none";
			document.getElementById("botaoAlterar").style.display = "none";
		</script>
  	</logic:empty>
  </logic:notPresent>	
</TABLE>
</html:form>
</body>
	
  <logic:present name="mensagem">
   <script>
		alert('<bean:write name="mensagem" />')			  			
  	</script>  	
  </logic:present>
</html:html>

Já essa, que aparentemente estão iguais ocorre o erro.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
 <html:base/>
<html:html>
<head>
<title>VEIC</title>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<LINK rel="stylesheet" type="text/css" href="/componentes/estilosApp.css">
<LINK rel="stylesheet" type="text/css" href="/veic/componentes/veic_style.css">
<SCRIPT language="JavaScript" src="/veic/componentes/veic_scripts.js"></SCRIPT>
<SCRIPT language="JavaScript">


	function Alterar(){
		if (document.getElementById('codigoParametro').value.length == 0){
			alert("Selecione uma Característica.")
		}else {
			document.manterCaracteristicaForm.action = '../../../manterCaracteristicaAction.do?parAcao=recuperar'; 
			document.manterCaracteristicaForm.submit();
		}	
	}	
	
	function Incluir(){
		document.manterCaracteristicaForm.action = "../../../manterCaracteristicaAction.do?parAcao=carregarInclusao";
		document.manterCaracteristicaForm.submit();	
	}
	
	function Excluir()	{
		if (document.getElementById('codigoParametro').value.length == 0){
			alert("Selecione um banco.")
		}else if(confirm("Tem certeza que deseja excluir este banco ?")){
			document.manterCaracteristicaForm.action = '../../../manterCaracteristicaAction.do?parAcao=excluir'; 
			document.manterCaracteristicaForm.submit();
		}		
	}
	function Pesquisar(){
		divListaItens.style.display = "";
		document.manterCaracteristicaForm.action = '../../../manterCaracteristicaAction.do?parAcao=pesquisar'; 
		document.manterCaracteristicaForm.submit();
	}
	function setaValor(valor){
		document.getElementById('codigoParametro').value = valor;		
	}
</SCRIPT>
</head>
<BODY class="fnd1">
<html:form action="/manterCaracteristicaAction">
	<input type="hidden" name="codigoParametro" id="codigoParametro">
	<!-- ####### Tabela de Alinhamento ####### -->
	<TABLE border="0" cellpadding="0" cellspacing="0" width="748">
		<TR>
			<TD colspan="2" height="5"></TD>
		</TR>
		<TR>
			<TD width="21"></TD>
			<TD>
				<!-- ####### Titulo ####### -->
				<DIV id="divTitulo" style="width:100%">
					<p>
						<FONT class="ttl2">Manuten&ccedil;&atilde;o</FONT><BR>
						<FONT class="ttl1">Manter Característica</FONT>
					</p>
				</DIV>
				<!-- ####### Pesquisa ####### -->
				<DIV id="divPesquisa" style="width:100%;padding-top:10px;">
					<TABLE border="1" borderColor="#990000" borderColorDark="white" cellpadding="3" cellspacing="0" rules="rows" frame="below" class="tab1" width="100%">
					    <TR>
						    <TD class='ttltab1' colspan=8 align='middle'>Opções de Pesquisa</TD>
						</TR>
					    <TR>
						    <TD width="100" class='txt1'><b>Característica:</b></TD>
							<TD>
								<html:text property="nome" styleClass="txt1" size="40" maxlength="40" />
							</TD>
							<TD width="60" class='txt1'><b>Situação:</b></TD>
							<TD>
								<html:select property="ativo" styleClass="frmCmb1">
									<html:option value="T">Todos</html:option>
									<html:option value="A">Ativo</html:option>
									<html:option value="I">Inativo</html:option>
								</html:select>
							</TD>
						</TR>
				    </TABLE>
				</DIV>
				<!-- ####### LISTA DE ITENS ####### -->
				<DIV id="divListaItens" style="width:100%;display: none; ">
				    
					<TABLE border="1" borderColor="#990000" borderColorDark="white" cellpadding="3" cellspacing="0" rules="rows" frame="below" class="tab1" width="100%">
						<TR align="center">
							<TD colspan="4" class="ttlTab1">Caracter&iacute;sticas</TD>
						</TR>
						<TR align="center">
							<TD width="20" class="ttlTab2">&nbsp;</TD>
							<TD class="ttlTab2" align="left"><B>Caracter&iacute;stica</B></TD>
							<TD width="150" class="ttlTab2"><B>Situação</B></TD>
							<TD width="10" class="ttlTab2">&nbsp;</TD>
						</TR>
					</TABLE>
					<DIV id="divScroll" style="height:140px">
						<TABLE border="1" borderColor="#990000" borderColorDark="white" cellpadding="3" cellspacing="0" rules="rows" frame="below" class="tab1" width="100%">
							<logic:present name="lista">
								<logic:iterate name="lista" id="conteudo">
									<TR align="center">
										<TD width="20" class="txtTab1">
										<input type="radio" name="itemSelecao" id="<bean:write property="codigo" name="conteudo"/>" value="radiobutton" class="frmTxt1" onclick="setaValor('<bean:write property="codigo" name="conteudo"/>')">
										</TD>
										<TD class="txtTab1" align="left"><bean:write property="nome" name="conteudo"/></TD>
										<TD width="150" class="txtTab1"><bean:write property="descricaoAtivo" name="conteudo"/></TD>
									</TR>
								</logic:iterate>
							</logic:present>
						</TABLE>
					</DIV>
				</DIV>
			<!-- ####### BOTOES ####### -->
			<DIV id="divBotoes">
				<DIV id="botaoIncluir"><INPUT type="Button" id="btoIncluir" name="btoIncluir" value="incluir" class="bto1" onclick="Incluir()"></DIV>
				<DIV id="botaoAlterar" style="display:none"><INPUT type="Button" id='btoAlterar' name='btoAlterar' value="alterar" class="bto1" onclick="Alterar()"></DIV>
				<DIV id="botaoExcluir" style="display:none"><INPUT type="Button" id='btoExcluir' name='btoExcluir' value="excluir" class="bto1" onclick="Excluir()"></DIV>
				<DIV id="botaoPesquisar"><INPUT type=button class=bto1 Value='pesquisar' id='bt_pesquisar' name='bt_pesquisar' align='left' onClick='Pesquisar()'></DIV>
			</DIV>
		</TD>
	</TR>
	<logic:present name="lista">
		<logic:notEmpty name="lista">
			<script>
				divListaItens.style.display = "";
				document.getElementById("botaoExcluir").style.display = "";
				document.getElementById("botaoAlterar").style.display = "";
			</script>
		</logic:notEmpty>
	</logic:present>
  
  <logic:notPresent name="lista">
  	<logic:empty name="lista">
  		<script>
	  		divListaItens.style.display = "none";
			document.getElementById("botaoExcluir").style.display = "none";
			document.getElementById("botaoAlterar").style.display = "none";
		</script>
  	</logic:empty>
  </logic:notPresent>
</TABLE>
</html:form>
</body>
  <logic:present name="mensagem">
   <script>
		alert('<bean:write name="mensagem" />')			  			
  	</script>  	
  </logic:present>
</html:html>

E ocorre a exception
[code]
[Erro de Servlet]-[Request[/manterCaracteristicaAction] does not contain handler parameter named &#39;parAcao&#39;.  This may be caused by whitespace in the label text.]: javax.servlet.ServletException: Request[/manterCaracteristicaAction] does not contain handler parameter named 'parAcao'.  This may be caused by whitespace in the label text.
Z

Pessoal meio consegui resolver adicionando esta linha no meu form

<input type="text" name="evitaSubmitAutomatico" style="display: none">

Agora não me pergunte porque a página não é mais submetida através do clique…

Se alguem poder explicar, agradeço.

Criado 8 de agosto de 2007
Ultima resposta 8 de ago. de 2007
Respostas 8
Participantes 4