使用由JavaScript下拉更改事件触发的参数重新加载页面 [英] Reload the page with parameter triggered by JavaScript dropdown change event

查看:88
本文介绍了使用由JavaScript下拉更改事件触发的参数重新加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要重新加载表单并预先选择所做的选择。以下是我的HTML表单:

 < form name ='vehicleform'> 

< select name ='vehiclelist'>
< option value =''>选择< / option>
< option value ='bus'>巴士< / option>
< option value ='bike'> Bike< / option>
< option value ='car'> Car< / option>
< / select>

< input type ='text'name ='current'>< / input>

< / form>

当用户第一次打开页面时,下拉框将位于选择选项,并且文本框(当前)将为空。

当用户从下拉列表中选择任何选项时,页面需要重新加载,并且应该选择该下拉列表项,并且该下拉列表的值应该位于文本输入字段中。 / p>

我需要做什么JavaScript函数?

解决方案

像这样:

 < select name ='soemname'id =myidonchange =document.location.href = 'page.php?var ='+ this.value> 
< option value =''>选择< / option>
< option value ='bus'>巴士< / option>
< option value ='bike'> Bike< / option>
< option value ='car'> Car< / option>
< / select>

< script type =text / javascript>
document.getElementById('myid')。value =<?php echo $ _GET ['var'];?>;
< / script>


I want a form to be reloaded and preselected with the selection made. Here's the HTML form I have:

<form name='vehicleform'>

<select name='vehiclelist'>
  <option value=''>Select</option>
  <option value='bus'>Bus</option>
  <option value='bike'>Bike</option>
  <option value='car'>Car</option>
</select>

<input type='text' name='current'></input>

</form>

When the user opens the page for the first time the dropdown box will be on the Select option by default and the textbox (current) will be empty.

When the user selects any option from dropdown the page needs to reload and that dropdown item should be selected and the value of that dropdown should be in the text input field.

What's the JavaScript function that I need to make this happen?

解决方案

Like this:

<select name='soemname' id="myid" onchange="document.location.href = 'page.php?var=' + this.value">
  <option value=''>Select</option>
  <option value='bus'>Bus</option>
  <option value='bike'>Bike</option>
  <option value='car'>Car</option>
</select>

<script type="text/javascript">
  document.getElementById('myid').value = "<?php echo $_GET['var'];?>";
</script>

这篇关于使用由JavaScript下拉更改事件触发的参数重新加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆