| | |
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
![]() |
•
•
Join Date: Sep 2008
Posts: 2
Reputation:
Solved Threads: 0
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
This is very weird. Code below
javascript Syntax (Toggle Plain Text)
function isNumeric(elem, helperMsg){ var numericExpression = /^[0-9]+$/; if(elem.value.match(numericExpression)){ return true; }else{ alert(helperMsg); elem.focus(); return false; } } function ischecked(elem, helperMsg){ if(elem.checked == true){ return true; }else{ alert(helperMsg); elem.focus(); return false; } } //document.myform.box1.checked == false function chkFormmt(frm){ if(isNumeric(frm.homevalue, "Please enter a number for your Home Value")){ if(isNumeric(frm.numautos, "Please enter a number for your number of Vehicles")){ if(isNumeric(frm.avgvalue, "Please enter a number for your average vehicle value")){ if(ischecked(frm.checkbox, "You must check that you have read the disclamer")){ return true; } } } } alert("here"); return false; }
•
•
Join Date: Sep 2008
Posts: 2
Reputation:
Solved Threads: 0
M#$%@r$&%@NG dreamweaver and I hate lable tags
Broken code below
Fixed code
Broken code below
html Syntax (Toggle Plain Text)
<label><br> <input type="checkbox" name="checkbox23" id="checkbox23"> <span class="style3"> I have read the Disclamer</span><br> <input name="button" id="button" value="Recalculate" type="submit"> </label> <br> </form>
Fixed code
html Syntax (Toggle Plain Text)
<label><br> <input type="checkbox" name="checkbox23" id="checkbox23"> </label> <span class="style3"> I have read the Disclamer</span><br> <input name="button" id="button" value="Recalculate" type="submit"> <br> </form>
Maybe this quick example can help you.
html Syntax (Toggle Plain Text)
<html> <head> <title><!--Sample--></title>
javascript Syntax (Toggle Plain Text)
<script type="text/javascript"> <!-- var numValue = /^\d{1,3}[\,]\d{3}$/; var numOfCar = /^d{1,2}$/; function validate( form ) { var mfields = []; if ( !numValue.test(form.hV.value )) { mfields[mfields.length] = 'Please enter the price value of your house! On this following format-\n(eg. 1,000).\n'; } 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' } if ( !numValue.test(form.vV.value )) { mfields[mfields.length] = 'Please enter the price value of your vehicle! On this following format-\n(eg. 1,000).\n'; } if ( !form.cB.checked ) { mfields[mfields.length] = 'You must check that you agreed to our terms and policies!\n'; } s = ''; s = ( mfields.length > 1 ) ? 's' : s; if ( mfields.length > 0 ) { helperMsg( mfields ); return false; } return true; } function helperMsg(mfields) { var errorMsg = '\nThere where some problem' + s + '!\n'; for ( var x = 0; x < mfields.length; x++ ) { var numErr = x + 1; errorMsg += '\n' + numErr + '. ' + mfields[x]; } alert(errorMsg); } //--> </script>
html Syntax (Toggle Plain Text)
</head> <body> <div> <form name="form1" action="#" onsubmit="return validate(this);"> <label>House Value <input type="text" name="hV" size="5" /></label><br /> <label>Number Of Vehichel <input type="text" name="nV" size="5" value="" /></label><br /> <label>Vehichel Value <input type="text" name="vV" size="5" value="" /></label><br /><br /> <label> <span> <!-- Disclaimers' Goes Here! --> </span><label><input type="checkbox" name="cB" value="" /> I Accept</label><br /><br /> <input type="submit" value="Submit" /><br /> </form> </div> </body> </html>
![]() |
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Drop Down Menu with Sucker Fish
- Next Thread: Help
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate automatically beta box browser bug calendar captchaformproblem checkbox child class close column createrange() css cursor decimal dependent design disablefirebug dom download dropdown editor element embed engine error events explorer ext file form forms google gwt gxt hiddenvalue highlightedword html htmlform ie8 iframe images index internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jump libcurl listbox math media microsoft mimic mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent paypal pdf php player post problem progressbar regex runtime scroll search security select shopping size software sql text textarea unicode w3c web website window windowofwords windowsxp wysiwyg \n





