2016-04-23 46 views
1

使用我想生成包含从下拉菜单中的值将被保存到一个PHP变量jQuery的获取值在PHP

<script> 
 
$(document).ready(function() 
 
{ 
 
    /* we are assigning change event handler for select box */ 
 
\t /* it will run when selectbox options are changed */ 
 
\t $('#dropdown_selector').change(function() 
 
\t { 
 
\t \t /* setting currently changed option value to option variable */ 
 
\t \t var option = $(this).find('option:selected').val(); 
 
\t \t /* setting input box value to selected option value */ 
 
\t \t $('$showoption').val(option); 
 
\t }); 
 
}); 
 
</script>
<? 
 
mysql_query("Select unit_price From products where id= '" . $id_value . "'"); 
 
\t \t \t \t \t \t \t \t \t \t while ($row = mysql_fetch_array($qquery)){ 
 
\t \t \t \t \t \t \t \t \t \t \t $unit = $row['unit_price']; 
 
\t \t \t \t \t \t \t \t \t \t } 
 
?> 
 

 
<select class="form-control" name="model" id="dropdown_selector" > 
 
<option value="1">1001</option> 
 
</select>

选择的值的查询
+0

考虑把它放在一个表单中,然后提交该表单或使用后端调用另一个php文件与查询东西 – Alexander

+0

我怎么能这样做 –

+0

检出$ .ajax或document.formname.submit(); – Alexander

回答

0

一个选项可能是获取select的值并使用同一页上的表单提交它。然后你可以在PHP中访问GET/POST参数。

另一个选择可能是获取选择变更的值,并向php页面发出请求,并根据该数据进行所需操作。它也可以返回任何你想要的数据。