PDA

View Full Version : Mutiple element id's


koujisedai
04-16-2007, 04:50 AM
Hey guys,

Just wondering if it is possible to return the value of multiple elements in one command? If that didn't make sense, which it probably doesn't because i'm an idiot, here is an example:

Original code is

var aText = document.getElementById('textarea1').value;


Which works nicely, but looking to return the value of three -

var aText = document.getElementById('textarea1', 'textarea2', 'textarea3').value;

Which doesn't work obviously. Just not sure how to do it, heh. Any help would be muchly appreciated! Thanks guys :)

_Aerospace_Eng_
04-16-2007, 06:08 AM
No its not possible doing it that way. You will have to use a forloop and assign each value to a different var or to an array cell.

david_kw
04-16-2007, 06:21 AM
As Aero said, in core javascript that isn't possible without some kind of loop. That said, many of the javascript libraries like Prototype (http://www.prototypejs.org) have that functionality. I think in Prototype it is done with

var aText = $('textarea1', 'textarea2', textarea3');

Just an FYI really.

david_kw

Kor
04-16-2007, 07:24 AM
You might use the prototype object (or a function-object) to have a final somehow similar syntax, but inside the prototype object you still need a loop. Javascript has no built-in classes, it uses constructors. prototype is one of them.

http://www.javascriptkit.com/javatutors/proto.shtml
http://www.w3schools.com/jsref/jsref_prototype_math.asp