简体   繁体   中英

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 );
    $(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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM