当我使用onchange时,如何提交具有选定值的表单

时间:2014-08-06 14:28:45

标签: javascript html forms select input

当我使用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>

1 个答案:

答案 0 :(得分:0)

只需使用submit()

function getAction() {
    formAction = document.myForm.myMenu[document.myForm.myMenu.selectedIndex].value;
    document.myForm.action = formAction;
    document.myForm.submit();
}