2016-04-23 34 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頁面發出請求,並根據該數據進行所需操作。它也可以返回任何你想要的數據。