Value i get so

var asc = $("#auth_site_check").val(); 

How to get checked

UPD

 function auth(){ var email = $("#auth_site_mail").val(); var pass = $("#auth_site_pass").val(); var result = document.getElementById('result'); if(email == "" || pass == ""){ result.innerHTML = '<div class="ininar">'+langtext+'</div>'; }else{ var auth = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; if(!email.match(auth)){ result.innerHTML = '<div class="ininar">'+mailno+'</div>'; } else{ $.ajax({ url: "script/auth.php", type: "POST", data:{email: email,pass: pass}, success: function(data, textStatus, jqXHR) { result.innerHTML = '<div class="ininar">'+data+'</div>'; } }); } } 
  • @NetSperes, And where do you need to check the checkbox? Guess from three attempts? PS It is better to check for emptiness with the operator === and the name of the variable ( auth ), which coincides with the name of the function - “this is cool”. - Deonis
  • I’m just not friends with js - Vlmake for a long time
  • @NetSperes, Make friends, if laziness does not prevail. And the above option came up? - Deonis
  • everything is mixed up ... I wonder what kind of hell do those who write if () {} else {if () {} else}} - zb '
  • deonis, no - Vlmake


2 answers 2

Those. do you need to get checkbox status? Then, the .prop () method will help you. We look at an example .

UPD Judging by the comments, read the documentation you bummer ...

 $('selector').click(function(){ if($(this).prop('checked')){ $.ajax({ url: '/path_to_handler/', method: 'POST', dataType: 'json', data: {asc: $(this).val()}, success: function(response){ alert('Oh, my God! It\'s time to read the manual!'); } }); } }); 
  • No, I just do not understand how to fasten yours to mine - Vlmake
  • @NetSperes, I haven’t seen yours, so I cannot give advice. Show the relevant code, but I'm going for a screwdriver so far. I think we'll screw it :) - Deonis

eg

 $("#auth_site_check").is(':checked'); 

or

 $("#auth_site_check:checked"); 
  • Well, it turns out so var asc = $ ("# auth_site_check: checked"); but not sent data: {asc: asc}, - Vlmake
  • and then you is (': checked'), or var asc = $ ('# auth_site_check: checked'). length> 0; - zb '
  • with $ ("# auth_site_check"). is (': checked'); writes false and var asc = $ ('# auth_site_check: checked'). length> 0; false - Vlmake
  • this is something you have. jsfiddle.net/oceog/fCPPU (specially without this made it clear) - zb '
  • can you id="auth_site_check" not one on the page? - zb '