Using Asp.net Webforms how can I validate that a checkbox has been checked. (I cannot do a postback) has to be in javascript (either custom - working with the existing validation controls for other fields. or using a .net validation control)
Thanks
Using Asp.net Webforms how can I validate that a checkbox has been checked. (I cannot do a postback) has to be in javascript (either custom - working with the existing validation controls for other fields. or using a .net validation control)
Thanks
in jquery
if ($('#checkBoxID').attr('checked'))
{
//code
}
in normal javascript
if (getElementById('checkBoxID').checked)
{
//code
}
You can use a CustomValidator control and specify an ClientValidationFunction javascript function.
Find more info here:
http://forums.aspfree.com/net-development-11/compare-validator-for-a-checkbox-121590.html
But if you're only doing client-side validation, the whole CustomValidator implementation might be a bit useless. Just validate the checkbox with javascript on the form submit.
if (document.getElementById("check_box_id").checked) {
// it is checked
}
else {
// it is not
}
Or with jQuery:
if ($(("#check_box_id").attr("checked") == true) {
// it is checked
}
else {
// it is not
}