JQuery-从选择选项中获取值以在 PHP 中使用


JQuery-Get value from select option to use in PHP

我想生成一个查询,其中包含从下拉菜单中选择的值,该值将保存到PHP变量中

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

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

另一种选择可能是获取更改时选择的值,并向 php 页面发出请求,该页面对该数据执行您想要的操作。它还可以返回您想要的任何数据。