简体   繁体   English

根据第一个下拉列表中的值填写第二个下拉列表

[英]Fill second dropdown based on value from the first

I have kinda asked this question before, but I have a drop down list that is filled using PHP/MYSQL, Now I want to change the dynamic values in another drop down box based on what is select here. 我之前曾问过这个问题,但是我有一个使用PHP / MYSQL填充的下拉列表,现在我想根据此处的选择在另一个下拉框中更改动态值。 Im guessing I need to use AJAX or JavaScript to get the value of the first drop down box, then some how use that to the next drop down. 我想我需要使用AJAX或JavaScript来获取第一个下拉框的值,然后介绍如何将其用于下一个下拉框。

Here is my current dropdown 这是我当前的下拉菜单

  <label for="order_quoteid">Quote</label>
    <select name="order_quoteid" id="myselect" class="myselect"  style="text-decoration: none; width: 258px; height: 26px;">
      <option value="0"<?php echo !$results['order']->order_quoteid ? " selected" : ""?>>(none)</option>
      <option value="0" > Stock </option>
    <?php foreach ( $results['quotes'] as $quote ) { ?>
      <option value="<?php echo $quote->quote_id ?>"
        <?php echo ( $quote->quote_id == $results['order']->order_quoteid ) ? " selected" : ""?>>
            <?php echo htmlspecialchars( ($quote->quote_code ).str_pad($quote->quote_id, 4, "0", STR_PAD_LEFT).' - '.$quote->quote_title )?>
      </option>
    <?php } ?>
  </select>

Once I get the id from this and get it back as a variable in php I could create a select statement and while loop to create the values for the second is this correct? 一旦我从中获得ID并将其作为php中的变量重新获取,我可以创建一个select语句,并在while循环中创建第二个值是否正确?

Can someone point in the direction of how to get the value from the first dropdown and get it into a second please. 有人可以指出如何从第一个下拉列表中获取值并将其转化为第二个方向的方向。

Thanks in advance. 提前致谢。

Ian 伊恩

EDIT-------------------------- 编辑 - - - - - - - - - - - - -

Am I Close? 我关闭吗? The alert show the right value, Its just trying to reload the page or 警报显示正确的值,它只是尝试重新加载页面或

  • in the right way that I can use the value in the PHP 以正确的方式可以在PHP中使用值

      <script> $(document).ready(function(){ $('#quoteselect').on( 'change', '.myselect', function() { var OrderQuoteVal = $(this).val(); alert(OrderQuoteVal); $.ajax({ type: "POST", // url: "saveStatus.php", data: { Orderquoteid : OrderQuoteVal }, success: function(data) { $('#quoteselect').reload('#quoteselect', function() {}); //$('#quoteselect').load('orders.php #quoteselect', function() {}); } }) }); }); </script> <li class="styled-select" id="quoteselect"> <?php $qqid = $_POST['Ordderquoteid']; ?> <label for="order_quoteid">Quote</label> <select name="order_quoteid" id="myselect" class="myselect" style="text-decoration: none; width: 258px; height: 26px;"> <option value="0"<?php echo !$results['order']->order_quoteid ? " selected" : ""?>>(none)</option> <option value="0" > Stock </option> <?php foreach ( $results['quotes'] as $quote ) { ?> <option value="<?php echo $quote->quote_id ?>" <?php echo ( $quote->quote_id == $results['order']->order_quoteid ) ? " selected" : ""?>> <?php echo htmlspecialchars( ($quote->quote_code ).str_pad($quote->quote_id, 4, "0", STR_PAD_LEFT).' - '.$quote->quote_title )?> </option> <?php } ?> </select> </li> 
  • In php, you can load your page showing only the first dropdown, and add a event so it submit the page, you then look if you have a $_post[var] set, if so, load the data for the second dropdown. 在php中,您可以加载仅显示第一个下拉列表的页面,并添加一个事件以提交页面,然后查看是否设置了$ _post [var],如果是,则加载第二个下拉列表的数据。

    I know it's not the most efficient way to do it, but if you don't want to use AJAX it can help. 我知道这不是最有效的方法,但是如果您不想使用AJAX,它会有所帮助。

    声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

    相关问题 用与第一个下拉列表相同的值填充第二个下拉列表 - Fill second dropdown with the same value as the first dropdown 在数据库中更改第一个下拉列表中的第二个下拉列表中填充值 - Fill value in second dropdown on changing of first from database 如何根据第一个下拉菜单中选择的值在第二个下拉菜单中选择一个值? 这两个值都来自数据库 - How to select a value in second dropdown based on value selected in first dropdown? both values are coming from the database 根据第一个下拉框的值预填充第二个下拉框 - prefill second dropdown box based on first dropdown box value 根据第一个下拉菜单的选定值填充第二个下拉菜单 - populate second dropdown based on selected value of first dropdown 根据第二个和第一个下拉菜单选择填充第三个下拉菜单 - Third dropdown populated based from second and first dropdown selections 根据第一个值在第二个Select2下拉菜单中显示选项 - Show option in second Select2 dropdown based on first value AngularJs 根据第一个下拉列表填充第二个下拉列表 - AngularJs populate second dropdown based on first dropdown 根据第一个下拉列表更改第二个下拉列表 - Change second dropdown based on first dropdown 根据“使用Java脚本的第一次”中的选择从第二个下拉菜单中删除项目 - Remove item from second dropdown based on selection in First using Javascript
     
    粤ICP备18138465号  © 2020-2024 STACKOOM.COM