简体   繁体   中英

JS changed in aspx from html

sorry I normally work through things like this (work related projects) on my own but do to circumstances I can't control I'm pretty much out of time, and ideas. I don't normally work in web scripting languages (i am learning c++ but I have had lots of html experience in the past so my boss put me on the job) but I managed to get some code made up to jump to a url based on 3 combo boxes input using javascript in html. I did not realize aspx though dose not handle js the same way that html does, until I completed the small project and put it in my aspx page. Here's the problem it seems to be small, but the go() function is no longer working correctly. I tested it by putting an alert box in the go() function and it seems the go function is still being called because the alert box showed on the button click, but I can't seem to get it to jump the the value in the third combo box. Does anybody know a quick fix that will work to change the url in aspx or any suggestions about other methods of completing this task? Any help is greatly appreciated, and thank you for your time.

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

I think you are trying to make the browser redirect to the url in the third drop down. In your "go()" function, replace

location =

with

window.location.href =

I think this will get you what you seek.

Also, a little constructive advice: people would probably be able to help you more if your code was more readable. I understand you were pushed into this by your management, and you said you come from a c++ background, so I don't blame you. It would be a lot easier for us, (and anyone else who has to maintain the code, including you) though, if you gave your variables more meaningful names. Names like "data_1", "data_1_1", "son", and "go()" make it more difficult to figure out what code should be doing. You might try a name like "goToVehiclePage()".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM