Javascript onclick not working in IE

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NeoTubNinja
    New Member
    • Mar 2007
    • 5

    Javascript onclick not working in IE

    I have a select statement with various numbers. Upon clicking on one of the options, you are sent to a page that puts the option value in a session and returns back to the previous page. When it gets back to the page it is supposed to write out a number of <div> tags based on the session variable. I don't know if its asp or IE, but regardless it works in firefox the way I want it to. The code that I'm using is:
    Code:
    <option onclick="window.location='uploadNum.asp?upNum=1';" <% If Session("uploadNum") = 1 Then Response.Write("selected='selected'") End If %>>1</option>
    I've tried any number of things to get it to work, such as putting "javascript :" before the "window.locatio n" and making the onclick call a function I made. None of the changes affect how it works in Firefox, but it still fails in IE.

    The asp in the code is just so that it starts out selected with the option that is equivalent to the session variable. Since the onclick doesn't work in IE, however, neither does the ASP.

    I know its the onclick, because I can manually put in the url and it works fine.

    Any advice as to how to fix it would be appreciated. :)
  • scripto
    New Member
    • Oct 2006
    • 143

    #2
    Originally posted by NeoTubNinja
    I have a select statement with various numbers. Upon clicking on one of the options, you are sent to a page that puts the option value in a session and returns back to the previous page. When it gets back to the page it is supposed to write out a number of <div> tags based on the session variable. I don't know if its asp or IE, but regardless it works in firefox the way I want it to. The code that I'm using is:
    Code:
    <option onclick="window.location='uploadNum.asp?upNum=1';" <% If Session("uploadNum") = 1 Then Response.Write("selected='selected'") End If %>>1</option>
    I've tried any number of things to get it to work, such as putting "javascript :" before the "window.locatio n" and making the onclick call a function I made. None of the changes affect how it works in Firefox, but it still fails in IE.

    The asp in the code is just so that it starts out selected with the option that is equivalent to the session variable. Since the onclick doesn't work in IE, however, neither does the ASP.

    I know its the onclick, because I can manually put in the url and it works fine.

    Any advice as to how to fix it would be appreciated. :)

    try "window.locatio n.href='uploadN um.asp?upNum=1' ;"

    Comment

    • mgast
      New Member
      • Sep 2006
      • 9

      #3
      You could also try using onchange="" on the select box. You can grab the selected option element with [select box object].selectedElemen t

      Comment

      • NeoTubNinja
        New Member
        • Mar 2007
        • 5

        #4
        Originally posted by scripto
        try "window.locatio n.href='uploadN um.asp?upNum=1' ;"
        Tried that already. Still fails to work with IE :(

        Comment

        • iam_clint
          Recognized Expert Top Contributor
          • Jul 2006
          • 1207

          #5
          Example:
          Code:
          <select onchange="window.location=this.value;">
          <option value="#">Select Location</option>
          <option value="http://www.google.com">google</option>
          <option value="uploadNum.asp?upNum=1">upload</option>
          </select>

          Comment

          • NeoTubNinja
            New Member
            • Mar 2007
            • 5

            #6
            It also appears that it wont read anything inside the onclick. I've tried an alert in there as well.

            In fact, ive tried onfocus, onchange(in the select tag), and some of the other "on"s, but doesnt seem to read whatever appears in there.

            I tested an alert by putting javascript in the header just to make sure it worked and it does. Maybe I have to add something inside script tags in header or include some javascript files? I don't know.

            Comment

            • NeoTubNinja
              New Member
              • Mar 2007
              • 5

              #7
              Originally posted by iam_clint
              Example:
              Code:
              <select onchange="window.location=this.value;">
              <option value="#">Select Location</option>
              <option value="http://www.google.com">google</option>
              <option value="uploadNum.asp?upNum=1">upload</option>
              </select>

              Good idea, but when it tries to load the page it goes to "blahblahbl ah/undefined" instead "blahblahbl ah/uploadNum.asp?u pNum=1".

              Same with google, says its undefined. That's in firefox. Non-responsive in IE.

              Comment

              • iam_clint
                Recognized Expert Top Contributor
                • Jul 2006
                • 1207

                #8
                works for me in both browsers.

                Comment

                • NeoTubNinja
                  New Member
                  • Mar 2007
                  • 5

                  #9
                  touche

                  Just made a test.html and test.asp with just that in it.
                  Works in both browsers.
                  Guess I'll have to find out what is wrong with my code.

                  Thanks for the help :)

                  Comment

                  • mgast
                    New Member
                    • Sep 2006
                    • 9

                    #10
                    Originally posted by iam_clint
                    Example:
                    Code:
                    <select onchange="window.location=this.options[this.selectedIndex];">
                    <option value="#">Select Location</option>
                    <option value="http://www.google.com">google</option>
                    <option value="uploadNum.asp?upNum=1">upload</option>
                    </select>
                    Try the code above

                    Comment

                    • iam_clint
                      Recognized Expert Top Contributor
                      • Jul 2006
                      • 1207

                      #11
                      you don't have todo selected index when your using a select box. you can just do this.value

                      Comment

                      Working...