mercredi 25 mars 2015

How to select and post multiple options from a dynamically generated checkbox?

I would like to enable multiple options to be selected from my checkbox and to be able to POST all selected options to my php function. I have tried to store the options in an array and then assign them. I am using window.location.assign which refreshes the page whenever an option is selected which doesn't allow for multiple selections.


My JS code



$(document).on("change", ".tablebox", function () {
var tbls = new Array();
$("input:checkbox[name='tbl[]']:checked").each(function() {tbls.push($(this).val());});
var tbl = tbls.join('|');
var yourDB = window.sessionStorage.getItem("db");
window.location.assign("index.php?db=" + yourDB + '&tbl=' + tbl);
});


My dynamically generated checkbox



echo '<input type="checkbox" name="tbl[]" id="' . $row [0] . '" value="' . $row [0] . '" class="tablebox" />';


PHP code



function describeTables() {
if (isset ( $_GET ['tbl'] )) {

$tbl = $_GET ['tbl'];
$db = $_GET ['db'];
$link = mysqli_connect ( 'localhost', 'root', '', $db );
$qry = "DESCRIBE $tbl";
}


How can I select and save the options then pass them to the function and get multiple results based on each id?





Aucun commentaire:

Enregistrer un commentaire