WebSpider member offline |
|
posts: |
147 |
joined: |
06/29/2006 |
from: |
Seattle, WA |
|
|
|
|
|
Javascript code for checkbox validation |
If, for example, you have a multiple checkboxes in a form and want to pop up an alert if none of them was checked, you can do it with the aid of property checked like the one below:
<SCRIPT type="text/javascript">
function checkCheckBoxes() {
if (document.getElementById("checkbox_dog").checked == false &&
document.getElementById("checkbox_cat").checked == false )
{
alert ('You did not choose any of the checkboxes yet.');
return false;
} else {
return true;
}
}
</SCRIPT>
<html>
<body>
<form onsubmit="return checkCheckBoxes();" action="">
<input type="checkbox" id="checkbox_dog" value="Dog">Dog</p>
<input type="checkbox" id="checkbox_cat" value="Cat">Cat</p>
<input type="submit" value="Submit" />
</form>
</body>
</html>
|
|
|
|
|
|