Jump to content

Mutiple element id's


rhyspaterson

Recommended Posts

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 :)

Link to comment
https://forums.phpfreaks.com/topic/47179-mutiple-element-ids/
Share on other sites

It actually depends on how you named your element's id. Issit in a sequence way? Eg:

textarea1

textarea2

textarea3

textarea4

.... so on....

 

If it is so, you can use loop to look through every elements:

var total_element = 10;

for(var i=1; i<total_element; i++){

    var aText = document.getElementById("textarea" + i).value;

}

Link to comment
https://forums.phpfreaks.com/topic/47179-mutiple-element-ids/#findComment-230272
Share on other sites

you could use the loop and place all the variables in a an array for use later on

 

var elementArray = new Array();
var total_element = 10;
for(var i=1; i<total_element; i++)
{
    elementArray[i-1]= document.getElementById("textarea" + i).value;
}

this is written this way because array all start at 0 --> elementArray[i-1]

 

Link to comment
https://forums.phpfreaks.com/topic/47179-mutiple-element-ids/#findComment-230284
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.