简体   繁体   中英

IE7/IE8 javascript drop down menu used to redirect not working

The error I see from IE7/IE8 in Jquery v1.7.2 and v.1.7.1 - i tried both:

 SCRIPT438: Object doesn't support property or method 'apply' 

My Code:

 <form>
 <select id="stateD" OnChange="showState()">
 <option value="none" selected="selected">==========</option>
 <option value="http://www.google.com">google</option>
 <option value="http://www.yahoo.com">Yahoo</option>
 </select>
 </form>

My Javascript - I have this pasted just below the webform:

<script type="text/javascript">
 function showState(){
oStates = document.getElementById("stateD");
var jLink = $("#stateD :selected").val();
if (jLink == undefined || jLink == "none" ){ alert("Please Select a State"); }
else{ document.location.href=jLink};
 }
</script>

I'm not using 2 libraries so i don't get why its having a problem. All that is supposed to happen is you select a url from the drop down menu and it auto sends you to that url that is in the value of the option tag. Works everywhere else, not sure why IE has to be such a jerk today.

I'd post a url but i can't at the moment. its private. has anyone encountered this issue before?

Try this simple code. Adapt a your situation, of course.

<script type="text/javascript">
<!--
window.location = "http://www.google.com/"
//-->
</script>

Only else{ document.location.href=jLink}; doesn't look fine here (because of the semicolon after } ) but I'm not sure if it's causing the error and rest of your code seems fine and oStates = document.getElementById("stateD"); is not used in your function so that line is unnecessary but it's not causing the error either but as an alternative to your problem you can use native/plain javascript instead of jQuery if you think it's jquery that causing the error and here the code for your showState function

function showState(){
    oStates = document.getElementById("stateD");
    var jLink = oStates.options[oStates.selectedIndex].value;
    if (jLink == undefined || jLink == "none" )
    {
        alert("Please Select a State");
    }
    else window.location=jLink;
 }​

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