Wednesday 21 July 2021

Pass values into Bootboxjs dialog confirm box

I have a PHP foreach loop like this:

<?php
foreach ($student->student as $d) {
    echo
    '<tr>' 
        '<td class="StudentID">' . $d->ID . '</td>' .
        '<td>' . $d->Date . '</td>' .
        '<td>' . $d->Name . '</td>' .
        '<td><a class="show-confirmation">'. "click to confirm" . '</a></td>' .
    '</tr>';
}
?>

I am using a bootbox js for a dialog box like this:

<script>
    $(document).on("click", ".show-confirmation", function(e) {
        var StudentID = $('#StudentID').val();

        bootbox.confirm("Confirm, student ID? " + StudentID, function(result) {
            console.log('This was logged in the callback: ' + result);
            console.log('StudentID: ' + StudentID);
        });
    });
</script>

what I am trying to accomplish is when I click on click to confirm which has class="show-confirmation", I want to get the value of $d->ID on the bootbox js confirm dialog box. Since this is a for each loop, I want to pass a new student id each time on the dialog confirm box.

On the confirm dialog, I want to see Confirm, student ID? + 15 which is the student id for that row.

What did I do?

  • I added a variable var StudentID = $('#StudentID').val(); hoping to fetch the student id value from the class StudentID eg: <td class="StudentID"> but it is undefined when I am accessing it.

Could someone please kindly guide me to accomplish this method?



from Pass values into Bootboxjs dialog confirm box

No comments:

Post a Comment