Javascript JS从html在aspx中更改

Javascript JS从html在aspx中更改,javascript,asp.net,html,Javascript,Asp.net,Html,很抱歉,我通常都是一个人处理类似的事情(与工作相关的项目),但我无法控制的情况下,我几乎没有时间和想法。我通常不使用Web脚本语言(我正在学习C++,但我过去有很多HTML经验,所以我的老板把我放在工作岗位上),但是我设法得到了一些代码,这些代码是基于HTML中的JavaScript输入的3个组合框跳转到URL的。直到我完成了这个小项目并把它放在我的aspx页面上,我才意识到aspx虽然不像html那样处理js。问题是它看起来很小,但go()函数不再正常工作。我通过在go()函数中放置一个警报框

很抱歉,我通常都是一个人处理类似的事情(与工作相关的项目),但我无法控制的情况下,我几乎没有时间和想法。我通常不使用Web脚本语言(我正在学习C++,但我过去有很多HTML经验,所以我的老板把我放在工作岗位上),但是我设法得到了一些代码,这些代码是基于HTML中的JavaScript输入的3个组合框跳转到URL的。直到我完成了这个小项目并把它放在我的aspx页面上,我才意识到aspx虽然不像html那样处理js。问题是它看起来很小,但go()函数不再正常工作。我通过在go()函数中放置一个警报框进行了测试,似乎仍然在调用go函数,因为按钮单击时显示了警报框,但我似乎无法让它跳转到第三个组合框中的值。是否有人知道一个快速修复,将工作,以改变在aspx的网址或任何关于完成这项任务的其他方法的建议?非常感谢您的帮助,谢谢您抽出时间

<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>

//第一个组合框
数据_1=新选项(“Acura”,“美元”);
//第二个组合框
数据_1_1=新选项(“MDX”、“-”;
//第三个组合框
data_1_1_1=新选项(“2007年”http://www.DawnEnterprises.co/2007-Acura-MDX-Accessories.aspx");
displaywhenempty=“”
值whenempty=-1
displaywhennotempty=“-选择-”
valuewhennotempty=0
功能更改(currentbox){
numb=currentbox.id.split(“”);
currentbox=numb[1];
i=parseInt(当前框)+1
while((eval(“typeof(document.getElementById)(\“combo”+i+“\”)!='undefined'))&&
(document.getElementById(“combo_”+i)!=null)){
son=document.getElementById(“组合”+i);
对于(m=son.options.length-1;m>0;m--)son.options[m]=null;
子选项[0]=新选项(显示Whenempty、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”)
如果(i==currentbox)中断;
i=i+1
}
以下=parseInt(当前框)+1
if((eval(“typeof(document.getElementById(\“combo\”+following+“\”)!='undefined'))&&
(document.getElementById(“combo_”+following)!=null)){
son=document.getElementById(“组合”+以下内容);
stringa=stringa+“uu2;”
i=0
while((eval(“typeof(“+stringa+i+”)='undefined'))| |(i==0)){
如果((i==0)和&eval(“类型(“+stringa+”0)='undefined'))
if(eval(“typeof(“+stringa+”1)=“未定义”)
eval(“子选项[0]=新选项(显示Whenempty,valuewhenempty)”)
其他的
eval(“子选项[0]=新选项(displaywhennotempty,valuewhennotempty)”)
其他的
eval(“子选项[“+i+”]=新选项(“+stringa+i+”.text,“+stringa+i+”.value)”)
i=i+1
}
//儿子
i=1
组合状态=“”
cstatus=stringa.split(“uquo”)
while(cstatus[i]!=null){
combostatus=combostatus+cstatus[i]
i=i+1
}
返回状态;
}
}
函数go(_值){
位置=
document.MMYSearch.combo2。
选项[document.MMYSearch.combo2.selectedIndex].value
}
车辆选择
选择车辆的品牌:

-挑选- 阿库拉 选择您车辆的型号:

选择您车辆的年份:


我认为您正在尝试将浏览器重定向到第三个下拉列表中的url。在“go()”函数中,替换

location =

我想这会让你得到你想要的


此外,还有一点建设性的建议:如果您的代码更具可读性,人们可能会为您提供更多帮助。我知道你被你的管理层推了进去,你说你来自C++背景,所以我不怪你。但是,如果您为变量指定了更有意义的名称,那么对我们(以及包括您在内的任何其他必须维护代码的人)来说,这会容易得多。像“data_1”、“data_1_1”、“son”和“go()”这样的名称使我们更难理解代码应该做什么。您可以尝试使用“goToVehiclePage()”这样的名称。

您的
go()
应该做什么?就目前而言,
location=“something”
对我来说没有多大意义:你奇怪的代码中充满了eval和strang类型检查,你能删除它们吗?那eval完全没有必要。如果可以替换为
typeof(document.getElementById(“combo”+i))!='未定义“
。是的,我同意对于命名约定来说,这更像是时间和概念上的事情。我已经有6年没有做过js了。谢谢你的帮助。我的问题是它应该是top.location.href!谢谢大家的帮助!在JS中需要注意的一件事是:如果键入一个不是保留字或已知对象的字,它将隐式地成为一个变量,在本例中为“location”,最终生成的代码将什么都不做。
window.location.href =