PDA

View Full Version : ensure that visitors choose also a checkbox


scsi
04-29-2003, 03:08 PM
hello,
i'm trying to add to the validation script for textbox also validation for checkbox, without good results.. here the code that works only for name and email fields..

<!-- form check field -->
function checkFields() {
missinginfo = "";

if (document.myform.name.value == "") {
missinginfo += "\n - Name";
}

if ((document.myform.email.value == "") ||
(document.myform.email.value.indexOf('@') == -1) ||
(document.myform.email.value.indexOf('.') == -1)) {
missinginfo += "\n - Email address";
}

if (document.myform.checkBOX.value == "") {
missinginfo += "\n - BOX";
}

if (missinginfo != "") {
missinginfo ="_____________________________\n" +
"You failed to correctly fill in your:\n" +
missinginfo + "\n_____________________________" +
"\nPlease re-enter and submit again!";
alert(missinginfo);
return false;
}
else return true;
}

thanks in advance for support

tamienne
04-29-2003, 03:26 PM
if (document.myform.checkBOX.checked == false) {
missinginfo += "\n - BOX";
}

unless you have a group of checkboxes then you'll want something like this...

var cbChecked = false;

for (idx=0;idx<document.myform.checkBOX.length;idx++) {
if (document.myform.checkBOX[idx].checked) {
cbChecked=true;
break;
}
}

if (!cbChecked) {
missinginfo += "\n - BOX";
}

scsi
04-29-2003, 04:28 PM
hi Tamienne thanks it works great!!