I have a checkbox where the values are dynamically populated from the data on my database. I would like to perform further queries based on the clicked checkbox, however I cant seem to retrieve the ID whenever I click on any of the checkboxes. I do not want to use a submit button. How can this be achieved??
My code.
function getDBlist() {
global $link;
$qry = ("SHOW DATABASES");
$res = mysqli_query ( $link, $qry );
while ( $row = mysqli_fetch_assoc ( $res ) ) {
echo '<input type="checkbox" name="db" id="' . $row ['Database'] . '" value="' . $row ['Database'] . '" />';
echo $row ['Database'];
}
}
getDBlist ();
My Script
$(document).on("change","checkbox", function() {
var val = $(this).val();
var id = this.id;
alert(val, id);
});
When I click on any of the checkboxes I don't get an alert with either the value or the ID. What am I doing wrong here? Could it be because of my dynamically generated ID?
Aucun commentaire:
Enregistrer un commentaire