Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: Accessing Form Fields Dynamically (Isaac S.)


Message #1 by jon stephens <zontar@m...> on Sun, 18 Feb 2001 18:34:31 -0700
Isaac,

Try this:

function button1_onclick()
{
  for(var i=0;i<=4;i++)
  {
    var sFieldName="put"+(i+1);
    document.frmTest.elements[sFieldName].value=ArrTest[i];
  }
}  

You had two problems with your function as written:

1. Square brackets, not parentheses, are used to access object
properties in this fashion, e.g.:

myObj.myProp

is equivalent to

myObj["myProp"]

and *not* myObj("myProp").

2. It helps if you remember that form elements are actually members of
its elements collection.

Good luck!

jon stephens
(Wrox Press Technical Reviewer and occasional lurker on this list :-)

-- 
--------------------------------
jon stephens
email: zontar@m...
voice: +1.480.966.1871
--------------------------------
What's The Buzz? http://buzz.builder.com/
--------------------------------

  Return to Index