2014-12-03 191 views
0

我們已經設置了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

歡迎來到StackOverflow。將來,請務必將您的問題稱爲**問題**。你的帖子沒有提出問題,但我回答了你所問的**。 – philtune 2014-12-03 21:16:22

回答

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/'], 
    ] 
    }; 
+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