getElementById help

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
taha
Forum Newbie
Posts: 17
Joined: Tue Nov 22, 2005 2:40 pm

getElementById help

Post by taha »

if i have the following line of code, could i somehow get the value of each textfield by assigning it to an array???

Code: Select all

function submitSave()
  {
     var iarray  = new Array();

     for (i=0; i<numItems; i++)
     {
         document.getElementById("textfields").value = iarray;         
     }
  }
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

This is JavaScript not PHP. Moved to client side ;)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

You're assigning the array to the value, rather than adding the value to the array ;)

Code: Select all

function submitSave()
  {
     var iarray  = new Array();

     for (i=0; i<numItems; i++)
     {
         iarray.push(document.getElementById("textfields").value);
     }
  }
This is obviously pseudo code you posted but I'm not sure what you're after. If you want the value of all text fields this works.... (hint: document.getElementsByTagName('foo'); )

Code: Select all

function submitSave()
  {
     var iarray  = new Array();
     var textFields = document.getElementsByTagName('textarea'); //Returns array of nodes
     for (var x in textFields)
     {
         iarray.push(textFields[x].value);
     }
     return iarray;
  }
Post Reply