Jump to content

Archived

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

djones

Get all IDs associated with all textareas

Recommended Posts

I'm using an Edit in place script to edi the contents of textareas on my page. The problem is I don't know the IDs because they are all dynamic. I have assigned a unique id to each one as they are printed on the page, but I need help getting the ID names for each textarea. This is what I started:

var x = document.getElementsByTagName('textarea');

for (var i=0;i<x.length;i++) {

EditInPlace.makeEditable({ id: x[i], type: 'textarea' });

}

Share this post


Link to post
Share on other sites
check this script out. you can modify it to do what you're after:
[code]
var x = document.getElementsByTagName('textarea');
var count = 0;
var list  = 0;
for (i = 0; i < x.length; i++) {
  myID = x[i].id;
  if (myID != '') {
    count++;
    list += myID + "\n";
  }
}

if (count > 0) alert(list);
else alert('none');
[/code]

this script, when run after the page has loaded, will check all textareas for ids. it will then show the list of all ids that have been pulled from the textareas on the page. if none of them have ids assigned, it will alert "none" to the screen.

hope this helps

Share this post


Link to post
Share on other sites
Works. Thanks. I wan't sure how to get the ids in the loop for each textarea
myID = x[i].id; // crucial part

Thanks!

Share this post


Link to post
Share on other sites
keep in mind that [i]typically[/i], you can access the value of nearly any attribute (e.g. name, alt, width, src, etc) by simply referring to that attribute like the ".id" above.

Share this post


Link to post
Share on other sites

×

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.