当我使用onchange时如何提交具有所选值的表单?
如何设置Action获取值?
我有这个
<script>
function getAction() {
formAction = document.myForm.myMenu.value;
document.myForm.action = formAction;
document.myForm.submit();
}
</script>
<form name="myForm" method="get" onsubmit="getAction();" action="">
<input type="text" name="q" size="70" maxlength="100" id="input" />
<select name=myMenu id="menu" onchange="submit();" >
<option value="https://www.google.com/search?q=" > Google</option>
<option value="http://www.bing.com/search?q=" >Bing</option>
<option value="https://next.duckduckgo.com/?q=" > DuckDuckGo</option>
<input type="submit" name="go" value="Search" id="button" >
</form>
答案 0 :(得分:0)
只需使用submit()
:
function getAction() {
formAction = document.myForm.myMenu[document.myForm.myMenu.selectedIndex].value;
document.myForm.action = formAction;
document.myForm.submit();
}