我想让用户选择访问他的网站的选项,我有以下代码,任何人都可以帮我纠正它;
<script type="text/javascript">
function onSubmitForm() {
document.selectDisplay.action = document.getElementById("selectwebiste").value;
return true;
}
</script>
<form method="get" id="uesfulwebsite">
<select id="selectwebiste">
<option value="http://www.google.com">Google</option>
<option value="http://www.yahoo.com">Yahoo</option>
<option value="http://www.facebook.com">facebook</option>
<option value="http://stackoverflow.com/">Stack Over Flow</option>
</select>
<input type="submit" value="Go!" />
</form>
答案 0 :(得分:0)
您的表单需要事件onsubmit =&#34; onSubmitForm();
<script type="text/javascript">
function onSubmitForm()
{
document.forms[0].action = document.getElementById("selectwebiste").value;
return true;
}
</script>
<form method="get" id="uesfulwebsite" onsubmit="onSubmitForm();">
<select id="selectwebiste">
<option value="http://www.google.com">Google</option>
<option value="http://www.yahoo.com">Yahoo</option>
<option value="http://www.facebook.com">facebook</option>
<option value="http://stackoverflow.com/">Stack Over Flow</option>
</select>
<input type="submit" value="Go!" />