Firefox is checking my checkbox after a return false for validation

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Sep 2008
Posts: 2
Reputation: southloven is an unknown quantity at this point 
Solved Threads: 0
southloven southloven is offline Offline
Newbie Poster

Firefox is checking my checkbox after a return false for validation

 
0
  #1
Sep 26th, 2008
I have a form that I am checking to see if a check box is checked. If it is not checked an alert pops up with an error message and when I click OK It checks the check box.

This is very weird. Code below
  1.  
  2. function isNumeric(elem, helperMsg){
  3. var numericExpression = /^[0-9]+$/;
  4. if(elem.value.match(numericExpression)){
  5. return true;
  6. }else{
  7. alert(helperMsg);
  8. elem.focus();
  9. return false;
  10. }
  11. }
  12. function ischecked(elem, helperMsg){
  13. if(elem.checked == true){
  14. return true;
  15. }else{
  16. alert(helperMsg);
  17. elem.focus();
  18. return false;
  19.  
  20. }
  21. }
  22. //document.myform.box1.checked == false
  23. function chkFormmt(frm){
  24. if(isNumeric(frm.homevalue, "Please enter a number for your Home Value")){
  25. if(isNumeric(frm.numautos, "Please enter a number for your number of Vehicles")){
  26. if(isNumeric(frm.avgvalue, "Please enter a number for your average vehicle value")){
  27. if(ischecked(frm.checkbox, "You must check that you have read the disclamer")){
  28. return true;
  29. }
  30. }
  31. }
  32. }
  33. alert("here");
  34. return false;
  35. }
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 2
Reputation: southloven is an unknown quantity at this point 
Solved Threads: 0
southloven southloven is offline Offline
Newbie Poster

Re: Firefox is checking my checkbox after a return false for validation

 
0
  #2
Sep 26th, 2008
M#$%@r$&%@NG dreamweaver and I hate lable tags



Broken code below
  1. <label><br>
  2. <input type="checkbox" name="checkbox23" id="checkbox23">
  3. <span class="style3"> I have read the Disclamer</span><br>
  4. <input name="button" id="button" value="Recalculate" type="submit">
  5. </label>
  6. <br>
  7. </form>

Fixed code
  1. <label><br>
  2. <input type="checkbox" name="checkbox23" id="checkbox23">
  3. </label>
  4. <span class="style3"> I have read the Disclamer</span><br>
  5. <input name="button" id="button" value="Recalculate" type="submit">
  6. <br>
  7. </form>
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: Firefox is checking my checkbox after a return false for validation

 
0
  #3
Sep 26th, 2008
Maybe this quick example can help you.


  1. <html>
  2. <head>
  3. <title><!--Sample--></title>
  1. <script type="text/javascript">
  2. <!--
  3. var numValue = /^\d{1,3}[\,]\d{3}$/;
  4. var numOfCar = /^d{1,2}$/;
  5. function validate( form )
  6. { var mfields = [];
  7. if ( !numValue.test(form.hV.value )) {
  8.  
  9. mfields[mfields.length] = 'Please enter the price value of your house! On this following format-\n(eg. 1,000).\n'; }
  10.  
  11. if ( !numOfCar.test( form.nV.value )) { mfields[mfields.length] = 'Please enter the number of your vehicle! With a maximun digits\' of 2 or less.\n' }
  12.  
  13. if ( !numValue.test(form.vV.value )) {
  14.  
  15. mfields[mfields.length] = 'Please enter the price value of your vehicle! On this following format-\n(eg. 1,000).\n'; }
  16.  
  17. if ( !form.cB.checked ) {
  18.  
  19. mfields[mfields.length] = 'You must check that you agreed to our terms and policies!\n'; }
  20.  
  21.  
  22.  
  23. s = '';
  24. s = ( mfields.length > 1 ) ? 's' : s;
  25. if ( mfields.length > 0 ) {
  26. helperMsg( mfields ); return false; } return true;
  27. }
  28.  
  29. function helperMsg(mfields)
  30. { var errorMsg = '\nThere where some problem' + s + '!\n';
  31. for ( var x = 0; x < mfields.length; x++ ) {
  32. var numErr = x + 1;
  33.  
  34. errorMsg += '\n' + numErr + '. ' + mfields[x]; } alert(errorMsg);
  35. }
  36. //-->
  37. </script>
  1. </head>
  2. <body>
  3. <div>
  4. <form name="form1" action="#" onsubmit="return validate(this);">
  5. <label>House Value&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  6. <input type="text" name="hV" size="5" /></label><br />
  7. <label>Number Of Vehichel&nbsp;<input type="text" name="nV" size="5" value="" /></label><br />
  8. <label>Vehichel Value&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  9. <input type="text" name="vV" size="5" value="" /></label><br /><br />
  10. <label>
  11. <span>
  12. <!-- Disclaimers' Goes Here! -->
  13. </span><label><input type="checkbox" name="cB" value="" />&nbsp;I Accept</label><br /><br />
  14. <input type="submit" value="Submit" /><br />
  15. </form>
  16. </div>
  17. </body>
  18. </html>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC