There is a checkbox. If it is marked in the check field of the table, the events were recorded as 1 if they were unmarked, then it wrote 0. How can this be done without sending the form, but in fact, the actual mark of this checkboxa?
Thank you in advance.
- Ie now they mark the checkbox and then click on the submit button? Do you need to change the state of the checkbox? - Shadow33
- Now there is just a checkbox that is out of shape. and it is necessary that he performed the specified actions simply by a change of state. - DaVinchi
1 answer
<input type = 'checkbox' onchange = 'save()' /> function save(){ $.ajax({ method: "POST", url: url, dataType: dataType }).done(function(answer){ }); }
If I understood everything correctly here is a simple implementation. The script is executed at any change of checkbox. Inside the script, you can determine the state of the checkbox using .prop( "checked" )
. Implementation on the server side did not write. If you need to write.
Read about AJAX here .
in the function it is better to get the value of the checkbox will look like this somewhere:
var checkboxState = false; if($(this).prop("checked") == true){ checkboxState = true; }
send to data
.
on the PHP side:
$stateCheckbox = $_POST['checkbox']; $sql = "UPDATE table SET checkbox = $stateCheckbox"; // Выполнение запроса
request without preparation just for the "view". Just the usual POST no magic at the end of the php script is desirable to respond to a successful completion, or an error. can be done with the usual: die(json_encode(['code'=>200,'msg'=>'ok']));
on the js side in the dataType specify json
- Thanks, as soon as I try - accomplish your goal. - DaVinchi
- If it's not difficult, just in case, the fireman, you can also use the server version, otherwise I’m a full zero in Ajax ( - DaVinchi
- @DaVinchi Changed the answer - Shadow33
- Thanks for the answer and for the recommendations on AJAX. Be sure to use the advice) - DaVinchi