Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

jquery - How can I pass the chosen value on a modal-box to 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>

And:

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...