submit form on checkbox select
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 );开发者_如何学Python
$(this).closest("form").submit();
});
Thanks.
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.
精彩评论