go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  Javascript code for checkbox validation
 
Subject: Javascript code for checkbox validation
Author: WebSpider
Posted on: 03/10/2009 08:49:32 PM

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>





References:

 


 
Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
 
Get your own forum today. It's easy and free.