0

i want to insert data into table when checkbox is checked and delete data from table when check box is uncheked for that i a am using this ajax code.. is there any event that will fire when checkbox changed and checkbox uncheked

code :

<script type="text/javascript">
$(function() {


//$(".tb11").click(function(){
$(document).on('click', '.clUname', function(event)
{
//Save the link in a variable called element

var element = $(this);
var table = $('#selecttable').val();
//Find the id of the link that was clicked
var del_id = element.attr("id");

//Built a url to send
//var info = 'id=' + del_id,'&selecttable=' + table
 if(confirm("Are You Sure You Want Delete This Record."))
          {

 $.ajax({
   type: "POST",
   url: "DeletePropertyGalleryData.php",
      data: 
            {
                id: del_id ,selecttable: table

            },
   success: function(){

   }
 });

 }

return false;

});

});
</script>
3
  • 1
    Search for checkbox events in google.. Commented Jan 9, 2014 at 6:28
  • i searched but didnt get any solution Commented Jan 9, 2014 at 6:29
  • What you mean by didnt get any solution. Copy pasting the above comment gave me a dozen of results. See this google.co.in/… Commented Jan 9, 2014 at 6:31

3 Answers 3

4

Try with Onchange it also catch the checkbox event

$(document).on('change', '.clUname', function(event)
{

});
Sign up to request clarification or add additional context in comments.

1 Comment

actually i was using click function thats why it was not working my check box cheked staus was not retaining ...
0

Assuming .clUname is your checkbos, use:

$('.clUname').change(function(){
    // AJAX code here    
});

More info.: http://api.jquery.com/change/

Comments

0

Checkbox check, uncheck will call jQuery .change() event.

If .clUname is checkbox class, then use following code :

jQuery('.clUname').change(function(){
     if(this.checked) {
         // Insert Data
     }else{
         // Delete Data
     }

})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.