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;
}

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>

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&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="hV" size="5" /></label><br />
<label>Number Of Vehichel&nbsp;<input type="text" name="nV" size="5" value="" /></label><br />
<label>Vehichel Value&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="vV" size="5" value="" /></label><br /><br />
<label>
<span>
<!-- Disclaimers' Goes Here! -->
</span><label><input type="checkbox" name="cB" value="" />&nbsp;I Accept</label><br /><br />
<input type="submit" value="Submit" /><br />
</form>
</div>
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.