[英]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
警报显示正确的值,它只是尝试重新加载页面或
<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.