Jquery check if asp flag is checked

Hi everyone, I have a checkbox. I want to check whether it was installed or not on the client side before the postback occurs. Check the box:

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

Thanks in advance, Laziale

UPDATE: The problem is that the page also has a button that is launched by js-code, and maybe I can add a line there to check if the checkbox is selected after clicking the button, otherwise a message will appear for the unchecked box:

function enterClick () {$ ('# Submit') press (). }

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

// I want to put checkbox logic here

Thanks again

+5
source share
4 answers

, - <input type="checkbox" class="checkbox" /> HTML , ASP.NET .

checkboxRules, . ASP.NET id + ( ) + checkboxRules, , .

jQuery , , "checkbox" CSS "checkbox".

$('input[type=checkbox] .checkbox').attr('checked')

. , CSS.

+1

...

if ($('#<%= checkboxRules.ClientID %>').is(':checked')) {
...
}
+9

, , :

var checked = $(".checkbox").is(':checked')
+2

Add a data attribute to your checkbox and use the hasClass function that jQuery provides. As below:

var isChecked = $('[data-checkbox]').hasClass('checkbox-selected');
<asp:CheckBox data-checkbox="" Text="Some Caption" runat="server" />
Run codeHide result
0
source

All Articles