Jump to content


Photo

Get all IDs associated with all textareas


  • Please log in to reply
3 replies to this topic

#1 djones

djones
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts
  • LocationWinston-Salem, NC

Posted 23 August 2006 - 12:52 PM

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' });

}

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 23 August 2006 - 01:12 PM

check this script out. you can modify it to do what you're after:
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');

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
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 djones

djones
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts
  • LocationWinston-Salem, NC

Posted 23 August 2006 - 01:23 PM

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

Thanks!

#4 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 23 August 2006 - 01:49 PM

keep in mind that typically, 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.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users