Checkbox - checked or not installed using jquery and mysql

I am currently making a system in which you need to check / uncheck the box. Every time it changes status, I need jquery to create and ajax call a page that updates the database.

My problem is how can I do this, so is it being updated?

Thanks in advance.

+7
source share
5 answers

For example, you can do this as follows:

First you should see if the checkbox is checked:

$("#yourSelector").live("click", function(){ var id = parseInt($(this).val(), 10); if($(this).is(":checked")) { // checkbox is checked -> do something } else { // checkbox is not checked -> do something different } }); 

You can download specific content through Ajax:

 $.ajax({ type: "POST", dataType: "xml", url: "path/to/file.php", data: "function=loadContent&id=" + id, success: function(xml) { // success function is called when data came back // for example: get your content and display it on your site } }); 
+13
source

What bit are you stuck with? You should probably have something like this ...

 $('#myCheckbox').click(function() { var checked = $(this).is(':checked'); $.ajax({ type: "POST", url: myUrl, data: { checked : checked }, success: function(data) { alert('it worked'); }, error: function() { alert('it broke'); }, complete: function() { alert('it completed'); } }); }); 
+6
source

Check if the checkbox is checked:

 if ( $('#id').is(':checked') ) { } 

This can be done in a function that is triggered by the onchange event.

 function checkCheckboxState() { if ( $('#id').is(':checked') ) { // execute AJAX request here } } 
+2
source

Is something like this possible?

 $('.checkbox').click(function (){ var val = $(this).is(':checked'); $.load('url_here',{status:val}); }); 
+2
source
 <input type="checkbox" name="foo" value="bar" class="checkIt"/> <script type="text/javascript"> $('.checkIt').bind('click', function() { if($(this).is(":checked")) { // checkbox is checked } else { // checkbox is not checked } }); </script> 

You may now have several flags.

+2
source

All Articles