How can I pass the chosen value on a modal-box to PHP?

南笙酒味 提交于 2019-11-29 16:23:06

add inline javascript:

<?php
    while($fetch = mysqli_fetch_array($r)) {                
        print "<tr>";
        print "  <td><a href=\"javascript:;\" onclick=\"$('#products_id_textbox').val('".$fetch[0]."');$('#products_modal_box').dialog('close');\">Choose</a></td>"; //--> How to return the value of $fetch[0]?
        print "  <td>" . $fetch[0] . "</td>"; //$fetch[0] == Product ID
        print "</tr>";
    }
?>

Instead using inline JS, you can write so (or something like this);

// php
while($fetch = mysqli_fetch_array($r)) {                
    print "<tr>";
    print "  <td><a rel='dialog' data-id='{$fetch[0]}'>Choose</a></td>";
    print "  <td>{$fetch[0]}</td>";
    print "</tr>";
}

// js
$(document).ready(function(){
...
$("a[rel=dialog]").each(function(){
   var id = this.getAttribute("data-id");
   $('#products_id_textbox').val(id);
   $('#products_modal_box').dialog('close');
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!