[英]How to pass html select option value through url in php
I'm trying to pass select option value through url.selection value come from mysql table.i want to pass that driver name to another page. 我正在尝试通过url.selection值从mysql表传递选择选项值。我想将该驱动程序名称传递给另一个页面。
<?php
//another select query goes here.
$query1= "SELECT * FROM driver WHERE status='Available'" ;
echo '<td>'.'<select name="driver">';
$result1= mysql_query($query1);
while($row1 = mysql_fetch_assoc($result1))
{
echo '<option value="'.$row1["name"].'">'.$row1["name"].'</option>';
}
echo '</select>'.'</td>';
echo'<a rel="facebox" href=db_confirm_booking.php?id='.$row["id"].'&driver='.$_POST['driver'].'>' . 'Confirm' . '</a>';
?>
Use jQuery. 使用jQuery。
Call change
event of the drop down. 下拉菜单的呼叫
change
事件。
$(function(){
$("[name=driver]").die('change').live('change', function(){
var driver = $(this).val();
if (typeof driver !== 'undefined') {
window.location.href = 'YOUR_FILE.php?driver='+driver;
}
});
});
And 和
in your YOUR_FILE.php
, get driver using $_GET['driver']
在您的
YOUR_FILE.php
,使用$_GET['driver']
获取驱动$_GET['driver']
Or if you want the form to be more secure, take a hidden variable. 或者,如果您希望表单更安全,请使用隐藏变量。
On change of driver
, assign it the value of driver
drop down. 更改
driver
,为其分配driver
下拉列表的值。
And post the form. 并发布表格。
In your PHP file, get it as $_POST['hid_driver']
. 在您的PHP文件中,将其获取为
$_POST['hid_driver']
。
U can add onclick function for the select field, try this way U可以为选择字段添加onclick函数,请尝试这种方式
<?php
//another select query goes here.
$query1= "SELECT * FROM driver WHERE status='Available'" ;
echo '<td>'.'<select name="driver" onchange="window.location.href=\'db_confirm_booking.php?driver=' . $_POST['driver'] . '&id=\'+this.value">';
$result1= mysql_query($query1);
while($row1 = mysql_fetch_assoc($result1))
{
echo '<option value="'.$row1["name"].'">'.$row1["name"].'</option>';
}
echo '</select>'.'</td>';
echo'<a rel="facebox" href=db_confirm_booking.php?id='.$row["id"].'&driver='.$_POST['driver'].'>' . 'Confirm' . '</a>';
?>
try this code 试试这个代码
<?php
//another select query goes here.
$query1= "SELECT * FROM driver WHERE status='Available'" ;
echo '<td>'.'<select name="driver"
onChange="window.location.href=this.value">';
$result1= mysql_query($query1);
while($row1 = mysql_fetch_assoc($result1))
{
echo '<option value="db_confirm_booking.php?id='.$row["id"].'&driver='.$_POST['driver'].'">"'.$row1["name"].'">'.$row1["name"].'</option>';
}
echo '</select>'.'</td>';
echo'<a rel="facebox" href=db_confirm_booking.php?id='.$row["id"].'&driver='.$_POST['driver'].'>
' . 'Confirm' . '</a>';
?>
example code 示例代码
<select onChange="window.location.href=this.value">
<option value="www.google.com">A</option>
<option value="www.aol.com">B</option>
</select>
<select name="sel" id="sel" onchange="seturl(this.value)">
<option value=""></option>
</select>
<script>
function seturl(id)
{
document.forms[0].action="test.php?driver="+id;
document.forms[0].submit();
}
</script>
It will reload the page with driver name in url. 它将使用url中的驱动程序名称重新加载页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.