//Creating a Fucntion for validation, pleae do not forget to write the opening javascript tag
function checkCheckBoxes() {
if (document.frmTest.CHKBOX_1.checked == false &&
document.frmTest.CHKBOX_2.checked == false &&
document.frmTest.CHKBOX_3.checked == false)
{
alert ('You didn\'t choose any of the checkboxes!');
return false;
}
else
{
return true;
}
}
//-->
</SCRIPT>
<form onsubmit="return checkCheckBoxes();" action="">
<input type="checkbox" name="CHKBOX_1" value="1">1</p>
<input type="checkbox" name="CHKBOX_2" value="2">2</p>
<input type="checkbox" name="CHKBOX_3" value="3">3</p>
<input type="submit" value="Submit!" />
</form>
Tutorial:
1. The Name of function : checkCheckBoxes
2. "document.frmTest.CHKBOX_1.checked"
Details:
"document" is the parent object of numerous other objects, such as "images", "forms" etc.
"frmTest" is a property of document object.
"CHKBOX_1, CHKBOX_2" etc is the name of input such as <input type="checkbox" name="CHKBOX_1" value="1">
function checkCheckBoxes() {
if (document.frmTest.CHKBOX_1.checked == false &&
document.frmTest.CHKBOX_2.checked == false &&
document.frmTest.CHKBOX_3.checked == false)
{
alert ('You didn\'t choose any of the checkboxes!');
return false;
}
else
{
return true;
}
}
//-->
</SCRIPT>
<form onsubmit="return checkCheckBoxes();" action="">
<input type="checkbox" name="CHKBOX_1" value="1">1</p>
<input type="checkbox" name="CHKBOX_2" value="2">2</p>
<input type="checkbox" name="CHKBOX_3" value="3">3</p>
<input type="submit" value="Submit!" />
</form>
Tutorial:
1. The Name of function : checkCheckBoxes
2. "document.frmTest.CHKBOX_1.checked"
Details:
"document" is the parent object of numerous other objects, such as "images", "forms" etc.
"frmTest" is a property of document object.
"CHKBOX_1, CHKBOX_2" etc is the name of input such as <input type="checkbox" name="CHKBOX_1" value="1">
3. <form onsubmit="return checkCheckBoxes();" action=""> by this line calling checkChechBoxes() function for the the Onclick Event.
Read more about javascript by www.netevolution.co.uk
Read more about javascript by www.netevolution.co.uk
No comments:
Post a Comment