Recent Posts

JavaScript Checkbox Validation

Tuesday 19 May 2015


Check box validation, Check box returns value ‘true’ if it’s selected, otherwise its returns ‘false’. For checkbox validation you don’t need to consider true parameter, JavaScript understands this parameter automatically. You can get the value of field or text box using their name or using their id. Below is script with pasted, you can customize accordingly you/ your requirement by changing field name or id name.

I have added two ways –
1. by using checkbox ID
2. by using checkbox field name.

Here is the sample code- "Java Script Check Box Validation"
You are good Person, YES? <input type="checkbox" id="Chkbox"> <button onclick="checkboxValidate()">Submit</button> You are good Person, YES? <input type="checkbox" name='ChkboxNme' id="Chkbox"> <button onclick="checkboxValidate2()">Save</button>' <script> function checkboxValidate() { if(document.getElementById("Chkbox").checked) alert('Yes! you are good person!!!') else { alert('Still confused ? please select checkbox.') ; return false } } function checkboxValidate2() { if(document.getElementsByName("ChkboxNme")[0].checked) alert('Yes! you are good person!!!') else { alert('Still confused ? please select checkbox.') ; return false } } </script>
Implementation -
You are good Person, YES? You are good Person, YES? '

No comments:

Post a Comment

 

Blogger JavaScript

Contact Us

Name

Email *

Message *

Tutorials