如何将模态框上的选定值传递给 PHP?

How can I pass the chosen value on a modal-box to PHP?(如何将模态框上的选定值传递给 PHP?)
本文介绍了如何将模态框上的选定值传递给 PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有初始化模态框的代码:

I've the code to initialize the modal-box:

<script>
var grid_modal_options = {
    height: 'auto',
    width: '80%',
    modal: true
};
function showProductsModalBox() {
    $("#products_modal_box").dialog(grid_modal_options);
    $("#products_modal_box").parent().appendTo('form:first');
}
</script>

<div id="products_modal_box" title="Products" style="display: none;">
  <div class="in">
    <div class="grid-12-12">
      <form id="products_modal_box_form" action="#" method="post">
    <table>
          <thead>
            <tr>
              <th>&nbsp;</th>
              <th>Product</th>
            </tr>
          </thead>
          <!-- Query for read mysql goes here (I skipped this line because it's not the main thing I'm gonna ask since it's run well) /-->
          <tbody>
          <?php
            //read the results
            while($fetch = mysqli_fetch_array($r)) {                
              print "<tr>";
              print "  <td><a href='#'>Choose</a></td>"; //--> How to return the value of $fetch[0]?
              print "  <td>" . $fetch[0] . "</td>"; //$fetch[0] == Product ID
              print "</tr>";
            }
          ?>
          </tbody>
        </table>
      </form>
    </div>
  </div>
</div>

还有:

<input type='text' id='products_id_textbox' name='products_id_textbox' />
<a href='#' onclick='showProductsModalBox(); return false;'>Choose products</a>

代码成功显示模态框.但是如何将用户选择的产品"返回到文本框products_id_textbox"?谢谢.

The code succeeds to show the modal box. But how to return the "Product" chosen by the user to the textbox "products_id_textbox"? Thanks.

推荐答案

添加内联javascript:

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>";
    }
?>

这篇关于如何将模态框上的选定值传递给 PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)