Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getbyname vs getbyid textarea 1

Status
Not open for further replies.

aldend123

Technical User
Feb 21, 2005
7
0
0
US
I have a textarea im trying to access through javascript
using getElementById("id").x i can access the textarea no problem, but changing it to getElementsByName("name").x, all x's are undefined (ie, value, name, rows,cols)

now of course the obvious answer is to just access through ID, but due to some circumstances, i cant. I must access it using the name attrib. Any idea why getElementsByName() wont work?
 
Well... if you only have an id on the textarea, then getElementsByName() will not work. Check that it has a name first. Send up some code showing the form element HTML and the javascript you are accessing if you still have no joy.

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
getElementsById returns a reference to the element you want to access. getElementsByName returns an array of all the page elements that have that name so you would not use something like document.getElementsByName('Name').value as the object is an array of elements.
You would have to get the object then figure out which element in that object you want and go after it's value property.
var myflds = document.getElementsByName('Name');
var myval = myflds[0].value;


It's hard to think outside the box when I'm trapped in a cubicle.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top