 | |
| southloven | Sep 26th, 2008 2:57 pm | |
| Firefox is checking my checkbox after a return false for validation 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
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;
}
|
| southloven | Sep 26th, 2008 4:00 pm | |
| Re: Firefox is checking my checkbox after a return false for validation M#$%@r$&%@NG dreamweaver and I hate lable tags
Broken code below
<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
<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> |
| essential | Sep 26th, 2008 11:53 pm | |
| Re: Firefox is checking my checkbox after a return false for validation Maybe this quick example can help you.
<html>
<head>
<title><!--Sample--></title> <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> </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> |
| All times are GMT -4. The time now is 12:11 pm. | |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC