开发者

.Net Make how to make sure a checkbox is checked

Using Asp.net Webforms how can I validate th开发者_JAVA技巧at 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


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.


in jquery

if ($('#checkBoxID').attr('checked'))
{
    //code
}

in normal javascript

if (getElementById('checkBoxID').checked)
{
    //code
}


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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜