我们设置了2个下拉列表。一旦用户从下拉列表2中选择了一个选项下拉列表1和选项,一旦选中它们并单击提交按钮,我们需要它来获取一个页面。
目前,代码设置为弹出窗口,并显示不是我们想要的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>
&#13;
<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>
&#13;
答案 0 :(得分:0)
而不是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/'],
]
};