[英]how can I add onchange function in a dropdown form to send data?
how can I send the data from a dropdown form with onchange function? 如何使用onchange函数从下拉表单发送数据?
Just like www.abc.com/index.php?version=(the value I suppose to send) 就像www.abc.com/index.php?version=(我想发送的值)
I can only use onChange to submit the data, but it is not I want. 我只能使用onChange提交数据,但这不是我想要的。
<form action="gp_data.php?gp_name=<?php echo $_GET['gp_name'] ?>&version=<?php echo $_POST['version'] ?>" method="POST">
<select name="version" onChange="this.form.submit()">
<option>Vers</option>
<?php while($subjectData = mysql_fetch_array($version)){ ?>
<option value="<?php echo $subjectData['version'];?>">
<?php echo $subjectData['version'];?>
</option>
<?php }?>
</select>
</form>
1- Form-data can be sent as URL variables (with method="get"). 1-表单数据可以作为URL变量发送(使用method =“ get”)。 GET to send sensitive data!
GET发送敏感数据! (will be visible in the URL) like www.abc.com/index.php?version=value
(将在URL中显示),例如www.abc.com/index.php?version=value
2- you can use hidden filed to send the store data on server. 2-您可以使用隐藏字段在服务器上发送存储数据。 that cannot be seen or modified by users when a form is submitted.
提交表单时用户无法看到或修改的内容。
<form action="index.php" method="GET">
<!----- Get the session value -->
<?php
$gp_name = $_SESSION['gp_name'];
?>
<!---- use the hidden file to send the session data within action ---->
<input type="hidden" name="gp_name" value="<?php echo $gp_name;?>">
<select name="version" onChange="this.form.submit()">
<option>Vers</option>
<?php while($subjectData = mysql_fetch_array($version)){ ?>
<option value="<?php echo $subjectData['version'];?>">
<?php echo $subjectData['version'];?>
</option>
<?php }?>
</select>
</form>
After submit the form, data will send by url like. 提交表单后,数据将通过url之类发送。
www.abc.com/index.php?gp_name=gp_name&version=Vers2
Try this 尝试这个
<form method="POST" action="">
<select name="version" id="myselect" onchange="this.form.submit()">
<option>Vers</option>
<?php while($subjectData = mysql_fetch_array($version)){ ?>
<option value="<?php echo $subjectData['version'];?>">
<?php echo $subjectData['version'];?>
</option>
<?php }?>
</select>
</form>
This task can be simply achieved by using Jquery. 使用Jquery可以轻松完成此任务。
First of all add Jquery on your page. 首先在页面上添加Jquery。
Then call On change event in Ready state. 然后在就绪状态下调用更改事件。
$(document).ready(function(){
$('#myselect').on('change', function(){
//Give your form an ID, i assume it is MyForm
$('#MyForm').submit();
});// Change
});// Ready
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.