Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
127
rated 0 times [  133] [ 6]  / answers: 1 / hits: 79738  / 13 Years ago, mon, may 16, 2011, 12:00:00

I am currently creating a system where it has to be possible to check/uncheck a checkbox. Everytime it changes status I need jQuery to make an AJAX call to a page, that updates the database.


How can I do this?


More From » jquery

 Answers
6

For example you can do it like this:



First you have to look 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 load specific content via 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
}
});

[#92219] Saturday, May 14, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jazmyne

Total Points: 503
Total Questions: 102
Total Answers: 99

Location: Svalbard and Jan Mayen
Member since Sun, Sep 25, 2022
2 Years ago
;