Selected Index not working on Safari browser 5.1.7, works fine in IE...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shravan88k
    New Member
    • Feb 2013
    • 6

    Selected Index not working on Safari browser 5.1.7, works fine in IE...

    Code:
    var elementObj = document.getElementById('code');
    alert("hi");
    var elementIndex = elementObj.selectedIndex;
    alert("hello");
    For the above code, any cod after the selectedIndex line does not execute on Safari browser 5.1.7

    Please help, or provide an alternative...
    Last edited by Meetee; Feb 13 '13, 11:47 AM. Reason: Use code tags [/CODE] around code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    what HTML element is the one with said ID?

    since any code after that doesn’t execute, there should be a message in the error console. (I stab a guess at "elementObj is null or not an object")

    Comment

    • shravan88k
      New Member
      • Feb 2013
      • 6

      #3
      it is a dropdown box... but the same code works fine on IE.... is getElementByID invalid on Safari Browser?

      Comment

      • shravan88k
        New Member
        • Feb 2013
        • 6

        #4
        TypeError: 'null' is not an object (evaluating 'elementObj.sel ectedIndex')

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          I guess you call it before that element is fully loaded.

          Comment

          • shravan88k
            New Member
            • Feb 2013
            • 6

            #6
            I used getElementsByNa me.. and it works now :)

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              I know you've solved this problem, but it'd be interesting to see your HTML code. I have a suspicion that you were trying to access the drop-down element with name "code" and no ID...

              Comment

              Working...