带链接的动态下拉菜单

问题描述:

我们已经设置了2个下拉菜单。一旦用户选择了下拉选项1和选项下拉选项2,一旦选择并且他们点击提交按钮,我们就需要它进入一个页面。带链接的动态下拉菜单

目前代码设置为弹出窗口并显示不是我们想要的URL名称。

希望能尽快听到某人的解答。

感谢, 马塞洛

<script> 
 
function setOptions(chosen) { 
 
var selbox = document.myform.opttwo; 
 
    
 
selbox.options.length = 0; 
 
if (chosen == " ") { 
 
    selbox.options[selbox.options.length] = 
 
new Option('Please select one of the options above first',' '); 
 
    
 
} 
 
if (chosen == "1") { 
 
    selbox.options[selbox.options.length] = 
 
new Option('UV Protection','http://example.com/portfolio-item/hand-cream-frag-free/'); 
 
    selbox.options[selbox.options.length] = 
 
new Option('Acne','http://example.com/portfolio-item/hand-cream-frag-free/'); 
 
    selbox.options[selbox.options.length] = 
 
new Option('Dry Skin','http://example.com/portfolio-item/hand-cream-frag-free/'); 
 
    selbox.options[selbox.options.length] = 
 
new Option('Eczema','http://example.com/portfolio-item/hand-cream-frag-free/'); 
 
    selbox.options[selbox.options.length] = 
 
new Option('Itchy Relief','http://example.com/portfolio-item/hand-cream-frag-free/'); 
 
    selbox.options[selbox.options.length] = 
 
new Option('Redness','http://example.com/portfolio-item/hand-cream-frag-free/'); 
 
    selbox.options[selbox.options.length] = 
 
new Option('Sensitive Skin','http://example.com/portfolio-item/hand-cream-frag-free/'); 
 
} 
 
if (chosen == "2") { 
 
    selbox.options[selbox.options.length] = 
 
new Option('UV Protection','http://example.com/portfolio-item/foot-balm/'); 
 
    selbox.options[selbox.options.length] = 
 
new Option('Acne','http://example.com/portfolio-item/foot-balm/'); 
 
    selbox.options[selbox.options.length] = 
 
new Option('Dry Skin','http://example.com/portfolio-item/foot-balm/'); 
 
    selbox.options[selbox.options.length] = 
 
new Option('Eczema','http://example.com/portfolio-item/foot-balm/'); 
 
    selbox.options[selbox.options.length] = 
 
new Option('Itchy Relief','http://example.com/portfolio-item/foot-balm/'); 
 
    selbox.options[selbox.options.length] = 
 
new Option('Redness','http://example.com/portfolio-item/foot-balm/'); 
 
    selbox.options[selbox.options.length] = 
 
new Option('Sensitive Skin','http://example.com/portfolio-item/foot-balm/'); 
 
} 
 
if (chosen == "3") { 
 
    selbox.options[selbox.options.length] = 
 
new Option('UV Protection','http://example.com/portfolio-item/body-lotion/'); 
 
    selbox.options[selbox.options.length] = 
 
new Option('Acne','http://example.com/portfolio-item/body-lotion/'); 
 
    selbox.options[selbox.options.length] = 
 
new Option('Dry Skin','http://example.com/portfolio-item/body-lotion/'); 
 
    selbox.options[selbox.options.length] = 
 
new Option('Eczema','http://example.com/portfolio-item/body-lotion/'); 
 
    selbox.options[selbox.options.length] = 
 
new Option('Itchy Relief','http://example.com/portfolio-item/body-lotion/'); 
 
    selbox.options[selbox.options.length] = 
 
new Option('Redness','http://example.com/portfolio-item/body-lotion/'); 
 
    selbox.options[selbox.options.length] = 
 
new Option('Sensitive Skin','http://example.com/portfolio-item/body-lotion/'); 
 
} 
 
} 
 
</script>
<form name="myform"><div class="centre"> 
 
<select name="optone" size="1" 
 
onchange="setOptions(document.myform.optone.options[ document.myform.optone.selectedIndex].value);"> 
 
<option value=" " selected="selected">I am</option> 
 
<option value="1">Someone who works with my hands</option> 
 
<option value="2">Someone who works with my feet</option> 
 
<option value="3">Someone who works with my body</option> 
 
</select><br /> <br /> 
 

 
<select name="opttwo" size="1"> 
 
<option value=" " selected="selected">and I need</option> 
 
</select> 
 

 
<input type="button" name="go" value="Value Selected" 
 
onclick="alert(document.myform.opttwo.options[ document.myform.opttwo.selectedIndex].value);"> 
 
</div></form>

+0

欢迎来到*。将来,请务必将您的问题称为**问题**。你的帖子没有提出问题,但我回答了你所问的**。 – philtune 2014-12-03 21:16:22

代替onclick="alert(...)",尝试onclick="window.location(...)"向浏览器发送到该页面。

更新回复:我们的谈话

为了使它更清洁,我愿意把所有选项成一个大 阵列 对象,你可以做各种各样的(容易)功能:

var options = { 
    "hands" : [ 
     ['UV Protection','http://example.com/portfolio-item/hand-cream-frag-free/'], 
     ['Acne','http://example.com/portfolio-item/hand-cream-frag-free/'], 
     ['Dry Skin','http://example.com/portfolio-item/hand-cream-frag-free/'], 
     ['Eczema','http://example.com/portfolio-item/hand-cream-frag-free/'], 
     ['Itchy Relief','http://example.com/portfolio-item/hand-cream-frag-free/'], 
     ['Redness','http://example.com/portfolio-item/hand-cream-frag-free/'], 
     ['Sensitive Skin','http://example.com/portfolio-item/hand-cream-frag-free/'], 
    ], 
    "feet" : [ 
     ['UV Protection','http://example.com/portfolio-item/foot-balm/'], 
     ['Acne','http://example.com/portfolio-item/foot-balm/'], 
     ['Dry Skin','http://example.com/portfolio-item/foot-balm/'], 
     ['Eczema','http://example.com/portfolio-item/foot-balm/'], 
     ['Itchy Relief','http://example.com/portfolio-item/foot-balm/'], 
     ['Redness','http://example.com/portfolio-item/foot-balm/'], 
     ['Sensitive Skin','http://example.com/portfolio-item/foot-balm/'], 
    ], 
    "body" : [ 
     ['UV Protection','http://example.com/portfolio-item/body-lotion/'], 
     ['Acne','http://example.com/portfolio-item/body-lotion/'], 
     ['Dry Skin','http://example.com/portfolio-item/body-lotion/'], 
     ['Eczema','http://example.com/portfolio-item/body-lotion/'], 
     ['Itchy Relief','http://example.com/portfolio-item/body-lotion/'], 
     ['Redness','http://example.com/portfolio-item/body-lotion/'], 
     ['Sensitive Skin','http://example.com/portfolio-item/body-lotion/'], 
    ] 
    }; 
+0

你好Philtune, 我改变了代码,因为你提到,但现在当我点击“值选定”按钮,它什么都不做。 我正在测试的网址是http://glysomed.bydecosta.com/test.php – 2014-12-03 21:41:06

+0

嗯,你的代码对我来说似乎有点复杂......我可能完全采用不同的路线。 – philtune 2014-12-03 21:57:22

+0

你会做什么...你会推荐什么? – 2014-12-03 22:01:56