Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery check if asp checkbox is checked

Hello everyone I have a checkbox I want to check if its checked or no on client side, before postback happens. Here is the checkbox:

 <asp:CheckBox runat="server" CssClass="checkbox" Checked="true" ID="checkboxRules" />

Thanks in advance, Laziale

UPDATE: The problem is that there is a button on the page too which is triggered by js code, and maybe I can add a line there to check if the checkbox is checked once the button is clicked, otherwise display message for unchecked checkbox:

function enterClick() { $('#SUBMIT').click(); }

var ishown = false;
$(document).ready(function () {
    $('#BUTTON').click(function (e) {

//I want to put the checkbox logic here

Thanks again

like image 815
Laziale Avatar asked Jul 13 '12 20:07

Laziale


People also ask

How can check checkbox is checked in jQuery in ASP NET?

jQuery Checkbox Checked Use the function prop() to check the checkbox using its id. $( '#myCheckbox' ). prop( 'checked' , true );

How do you check a checkbox is checked or not in jQuery?

To check whether a Checkbox has been checked, in jQuery, you can simply select the element, get its underlying object, instead of the jQuery object ( [0] ) and use the built-in checked property: let isChecked = $('#takenBefore')[0]. checked console. log(isChecked);

How do you check if the checkbox is checked or not?

Checking if a checkbox is checked First, select the checkbox using a DOM method such as getElementById() or querySelector() . Then, access the checked property of the checkbox element. If its checked property is true , then the checkbox is checked; otherwise, it is not.


1 Answers

try...

if ($('#<%= checkboxRules.ClientID %>').is(':checked')) {
...
}
like image 81
Suave Nti Avatar answered Nov 05 '22 08:11

Suave Nti