Link to home
Start Free TrialLog in
Avatar of TheCommunicator
TheCommunicatorFlag for United States of America

asked on

GetElementbyName in Javascript

Hi Guys,

I have following small code snipped in Javascript

 
var something = document.getElementsByName('key');


         for(obj in something) {
                alert(obj.value)

Open in new window


Here the var "Something " definately has tow values and when I do obj.value for each one then it comes back as undefined. BUt when I do something[0].value then it returns the real value.  I am not sure what is wrong with this code?
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TheCommunicator

ASKER

Thank you so much that worked any reasoning on why the other did nto work?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes but can't is read through that array using for(obj in something)?

look like not
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zappafan2k2
zappafan2k2

sorry, I meant to add that in your original example, you would want to write
for(obj in something) {
                alert(something[obj].value)
  }

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you so much guys that was useful information.