0

I have a table listing various line items. Each row has a checkbox. I decided to add a form for each line's checkbox, because I need to submit only one value when it is checked or unchecked.

I tried the following and indeed I get form submission, but how do I update my db? (I use PHP)

$(".rowChkeckBox").click( function(e){
    $(".chrowChkeckBoxkBx").val( e.value );
    $(this).closest("form").submit();
});

Thanks.

3
  • 1
    Are you looking for a full blown tutorial? Or is there some php code that you tried, and want help with? Commented Feb 22, 2011 at 18:21
  • 1
    You will need to post data through an AJAX request. Commented Feb 22, 2011 at 18:22
  • Similar post stackoverflow.com/questions/1760079/… Commented Feb 22, 2011 at 18:22

1 Answer 1

1

You need to use AJAX for that.

jQuery comes with an own AJAX class (See http://api.jquery.com/category/ajax/) Fill an AJAX request with the data of your form elements and then send it to a PHP file that is updating the database.

You don't even need to use forms for that, just listen to the click-event of the checkboxes and run that AJAX request once it is clicked.

After that you may update your table (HTML) using $(this) as your clicked checkbox (You can use jQuery's traversing methods to get to an element next to it etc.)

In the PHP file you need to parse the data of your elements via the $_POST or $_GET superglobal and write them into a database with SQL queries (http://php.net/manual/de/book.mysql.php)

I hope I understood your problem.

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

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.