Get asp.net CheckBox value via jquery (true / false)

received a response syntax error

I want to get the asp.net flag value via jquery if it was selected return true, otherwise false. I'm doing it: -

var ApprovalRequired = $('<%= chkRequired.ClientID %>').is(':checked'); // also var ApprovalRequired = $('<%= chkRequired.ClientID %>').val(); 

and checkbox return in html as

  <input id="ctl00_ContentPlaceHolder1_chkRequired" type="checkbox" name="ctl00$ContentPlaceHolder1$chkRequired" checked="checked"> 

in any case, its return is false. Any idea to get true if the checkbox is checked and false on unchecked

+6
source share
1 answer

You forgot # in your selector:

 $('#<%= chkRequired.ClientID %>').is(':checked'); 

This should work

+16
source

Source: https://habr.com/ru/post/944148/


All Articles