By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,261 Members | 1,674 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,261 IT Pros & Developers. It's quick & easy.

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

P: 6
Expand|Select|Wrap|Line Numbers
  1. var elementObj = document.getElementById('code');
  2. alert("hi");
  3. var elementIndex = elementObj.selectedIndex;
  4. 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...
Feb 13 '13 #1

✓ answered by shravan88k

I used getElementsByName.. and it works now :)

Share this Question
Share on Google+
6 Replies


Dormilich
Expert Mod 5K+
P: 8,639
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")
Feb 13 '13 #2

P: 6
it is a dropdown box... but the same code works fine on IE.... is getElementByID invalid on Safari Browser?
Feb 14 '13 #3

P: 6
TypeError: 'null' is not an object (evaluating 'elementObj.selectedIndex')
Feb 14 '13 #4

Dormilich
Expert Mod 5K+
P: 8,639
I guess you call it before that element is fully loaded.
Feb 14 '13 #5

P: 6
I used getElementsByName.. and it works now :)
Feb 14 '13 #6

acoder
Expert Mod 15k+
P: 16,027
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...
Feb 14 '13 #7

Post your reply

Sign in to post your reply or Sign up for a free account.