| Author |
How to handle condition in onClick?
|
S Man
Greenhorn
Joined: Apr 18, 2006
Posts: 2
|
|
Hi there, I have a list of rows in my jsp. Every row has the field "sequenceId". The user has the possibility to click on a navigation icon, placed at the beginning of every row, for further processing. Before further processing, I have to validate, if the User has entered a "sequenceId". I did the implementation with the following code: <script type="text/javascript"> function validate() { var fsequenceId=document.getElementById("sequenceId").value submitOK="true" if (fsequenceId.length<1) { alert("Field sequenceId is mandatory.") submitOK="false" } if (submitOK=="false") { return false } } </script> This is the function icon at the beginning of every row: lt&;a href="#" onKlick='<%= "validate(); document.myForm" + addressSelectionListIndex + ".submit();" %>' /> <img border="0" src="<%= request.getContextPath() %>/images/Funktions_Icons/activ.gif" alt="<bean:message key="tooltip"/>"> </a> Now I have 2 Problems: 1. My validate() method validates always the first "sequenceId" of the list. OK, I'll fix this later. 2. The Action (form submit) after the validate() method within the onClick Attrbite should only be processed, if the return Code of validate() was boolean TRUE. Any suggestions how I can do that? Regards, Marco
|
 |
Purushoth Thambu
Ranch Hand
Joined: May 24, 2003
Posts: 425
|
|
Try adding return keyword before the function call like: "return validate();..."
|
 |
S Man
Greenhorn
Joined: Apr 18, 2006
Posts: 2
|
|
Hmm, after having added "return" I'm not able to submit my form any longer ?! It looks like that the form submit is never processed after having completed the validate() routine. <a href="#" onKlick='<%= "return validate();document.newForm" + addressSelectionListIndex + ".submit();" %>' /> <img border="0" src="<%= request.getContextPath() %>/images/Funktions_Icons/tools_aktiv.gif" alt="<bean:message key="tooltip"/>"> </a> Any suggestions?
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
well you are not returning true from your function. Eric
|
 |
 |
|
|
subject: How to handle condition in onClick?
|
|
|