[英]get value of select box without submitting a form
hi i want to get the value the user selected from the dropdown menu without submitting a form and save it in a php variable any ideas ?? 嗨,我想获得用户从下拉菜单中选择的值,而无需提交表单并将其保存在php变量中的任何想法?
<select name="car" value="Select" size="1">
<?php
$sql = "SELECT fullname FROM users";
$result = mysql_query($sql) or die (mysql_error());
while ($row = mysql_fetch_array($result))
{
$name=$row["fullname"];
$options .= '<option value="'.$name.'">'.$name.'</option>';
}
?>
<?php echo $options; ?>
</option>
</select>
I don't think you fully understand how PHP works server side, but to get the value of a dropdown menu without submitting it you'll need Javascript ( jQuery makes everything easier). 我认为您不完全了解PHP如何在服务器端工作,但是要获得下拉菜单的价值而不提交,您将需要Javascript( jQuery使一切变得更容易)。 From there you just send an AJAX request using JSON as data format and retrieve it from PHP with json_decode
. 从那里,您只需使用JSON作为数据格式发送AJAX请求,然后使用json_decode
从PHP检索它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.