HTML/Javascript:从选定字段重定向URL

HTML/Javascript:从选定字段重定向URL,javascript,html,Javascript,Html,下面的选择框工作得非常好。它根据所选选项重定向 <select name="redirect" onChange="window.document.location.href=this.options[this.selectedIndex].value;" value="GO"> <option selected="selected">Select One</option> <option value="http://www.google.c

下面的选择框工作得非常好。它根据所选选项重定向

<select name="redirect" onChange="window.document.location.href=this.options[this.selectedIndex].value;" value="GO">
   <option selected="selected">Select One</option>
   <option value="http://www.google.com">Google</option>
   <option value="http://www.gmail.com">Gmail</option>
 </select>

选择一个
谷歌
Gmail
但我有一个复杂的下拉框,如下所示:

<select name="menu" onChange="window.document.location.href=this.options[this.selectedIndex].value;" value="GO">
    <option value="">Select Project</option>
    <option value="http://www.google.com">Type 1</option>
    <option value="Type 2">Type 2</option>
    <option value="Type 3">Type 3</option>
</select>
<select name="menu" onChange="javascript: if (this.value == 'http://www.google.com'){window.document.location.href=this.options[this.selectedIndex].value;}else{document.forms['myform'].submit();} " value="GO">
<option value="">Select Project</option>
<option value="http://www.google.com">Type 1</option>
<option value="Type 2">Type 2</option>
<option value="Type 3">Type 3</option>
</select>

选择项目
类型1
类型2
类型3
我知道上面的选择框没有意义,因为我使用onChange重定向,并使用type 2和type 3作为选项

问题:当我选择类型1时,它应该重定向到google,否则如果选择类型2或类型3,它的值应该提交到我的表单中


我们如何才能做到这一点。谢谢你

你应该试试这样的东西:

<select name="menu" onChange="window.document.location.href=this.options[this.selectedIndex].value;" value="GO">
    <option value="">Select Project</option>
    <option value="http://www.google.com">Type 1</option>
    <option value="Type 2">Type 2</option>
    <option value="Type 3">Type 3</option>
</select>
<select name="menu" onChange="javascript: if (this.value == 'http://www.google.com'){window.document.location.href=this.options[this.selectedIndex].value;}else{document.forms['myform'].submit();} " value="GO">
<option value="">Select Project</option>
<option value="http://www.google.com">Type 1</option>
<option value="Type 2">Type 2</option>
<option value="Type 3">Type 3</option>
</select>

选择项目
类型1
类型2
类型3
这里是document.forms['myform'].submit();。。。。您可以使用您的表单名称id更改myForm;)


Saludos

html就像您想要的那样:

<form name="fm_memu">
    <input type="text" name="ipt_menu" value=""/>
</form>
<select name="menu" onChange="if(this.selectedIndex){if(this.selectedIndex < 2){window.document.location.href=this.value;}else{window.document.forms['fm_memu']['ipt_menu'].value=this.value;}}" value="GO">
    <option value="">Select Project</option>
    <option value="http://www.google.com">Type 1</option>
    <option value="Type 2">Type 2</option>
    <option value="Type 3">Type 3</option>
</select>

选择项目
类型1
类型2
类型3

在onChange的else部分,我需要将值存储在select标记中,而不是发送警报。我不想发送任何警报,如果它的值为google,我将重定向,或者存储其余的。我将警报设置为示例模式…而不是警报,您可以放置所需的代码;)。。。。我想你可以理解……对不起……我要编辑答案;)