<script language="JavaScript" type="text/javascript">
// first combo box
data_1 = new Option("Acura", "$");
// second combo box
data_1_1 = new Option("MDX", "-");
// third combo box
data_1_1_1 = new Option("2007", "http://www.DawnEnterprises.co/2007-Acura-MDX-Accessories.aspx");
displaywhenempty=""
valuewhenempty=-1
displaywhennotempty="-select-"
valuewhennotempty=0
function change(currentbox) {
numb = currentbox.id.split("_");
currentbox = numb[1];
i=parseInt(currentbox)+1
while ((eval("typeof(document.getElementById(\"combo_"+i+"\"))!='undefined'")) &&
(document.getElementById("combo_"+i)!=null)) {
son = document.getElementById("combo_"+i);
for (m=son.options.length-1;m>0;m--) son.options[m]=null;
son.options[0]=new Option(displaywhenempty,valuewhenempty)
i=i+1
}
stringa='data'
i=0
while ((eval("typeof(document.getElementById(\"combo_"+i+"\"))!='undefined'")) &&
(document.getElementById("combo_"+i)!=null)) {
eval("stringa=stringa+'_'+document.getElementById(\"combo_"+i+"\").selectedIndex")
if (i==currentbox) break;
i=i+1
}
following=parseInt(currentbox)+1
if ((eval("typeof(document.getElementById(\"combo_"+following+"\"))!='undefined'")) &&
(document.getElementById("combo_"+following)!=null)) {
son = document.getElementById("combo_"+following);
stringa=stringa+"_"
i=0
while ((eval("typeof("+stringa+i+")!='undefined'")) || (i==0)) {
if ((i==0) && eval("typeof("+stringa+"0)=='undefined'"))
if (eval("typeof("+stringa+"1)=='undefined'"))
eval("son.options[0]=new Option(displaywhenempty,valuewhenempty)")
else
eval("son.options[0]=new Option(displaywhennotempty,valuewhennotempty)")
else
eval("son.options["+i+"]=new Option("+stringa+i+".text,"+stringa+i+".value)")
i=i+1
}
//son.focus()
i=1
combostatus=''
cstatus=stringa.split("_")
while (cstatus[i]!=null) {
combostatus=combostatus+cstatus[i]
i=i+1
}
return combostatus;
}
}
function go(the_value) {
location =
document.MMYSearch.combo2.
options[document.MMYSearch.combo2.selectedIndex].value
}
</script>
<form id="MMYSearch" action="../../../js/MMYSearch.js" name="MMYSearch">
<h4>Vehicle <span class="selection">Selection</span></h4>
<p>Select the Make of your vehicle:</p>
<select name="combo0" id="combo_0" onchange="change(this);" style="width:230px;">
<option value="value1">-select-</option>
<option value="value2">Acura</option>
</select>
<p>Select the Model of your vehicle:</p>
<select name="combo2" id="combo_1" onchange="change(this);" style="width:230px;">
</select>
<p>Select the Year of your vehicle:</p>
<select name="combo2" id="combo_2" onchange="change(this);" style="width:230px;">
</select>
<div>
<input type="button" name="Select" value="Select" onclick="go()" />
</div>
</form>
答案 0 :(得分:1)
我认为您正在尝试将浏览器重定向到第三个下拉菜单中的网址。在“go()”函数中,替换
location =
与
window.location.href =
我认为这会让你得到你想要的东西。
此外,还有一些建设性的建议:如果您的代码更具可读性,人们可能会更多地帮助您。我知道你被管理层推到了这里,你说你来自c ++背景,所以我不怪你。对于我们(以及其他任何必须维护代码的人,包括你),如果你给你的变量更有意义的名字,那将会容易得多。像“data_1”,“data_1_1”,“son”和“go()”这样的名称使得找出应该执行的代码变得更加困难。您可以尝试使用“goToVehiclePage()”之类的名称。