[TriLUG] Stuck in a rut

Rodney Radford rradford at mindspring.com
Tue Sep 15 16:19:22 EDT 2009


I think what you want is the Javascript eval() function that just evaluates whatever string is passed to it.  So you should be able to pass in the name of your variable and it will evaulate to the value of that variable.  You can also use eval to do assignments.

Check out: http://www.w3schools.com/jsref/jsref_eval.asp

-----Original Message-----
>From: Brian McCullough <bdmc at bdmcc-us.com>
>Sent: Sep 15, 2009 4:08 PM
>To: Triangle Linux Users Group discussion list <trilug at trilug.org>
>Subject: [TriLUG] Stuck in a rut
>
>
>Folks,
>
>I know that I can't see the forest because I have my head stuck in a tree, so I hope somebody can gently put me back on the path.
>
>( This is a Javascript question. )
>
>
>I have a form, something like:
>
>
><form name='example' >
><p >some text</p >
><input type='text' name='ex-1' >
><input type='text' name='ex-1' >
><p >some text</p >
><input type='text' name='ex-2' >
><input type='text' name='ex-2' >
><input type='text' name='ex-2' >
><p >some text</p >
><input type='text' name='ex-3' >
></form >
>
>
>As you can see, I have some arrays of text strings being collected.  While I know the number of groups to expect, the number of elements in each group is variable.
>
>Not necessarily describing the problem well, but I would like to be able to address each element through JS and manipulate them.
>
>I have tried:
>
>var name = 'ex-' + counter;
>var len  = document.example.name.length;
>
>and get variations on "undefined".
>
>I have tried:
>
>var name = 'document.example.ex-' + counter;
>var len  = name.length;
>
>and I get the length of "name," not the number of elements in the array.
>
>I tried a while loop, using "name" as defined above, and checking for "name[i]" to be undefined, but it seems to be always defined, no matter what input I give it.
>
>
>Any bright ideas?
>
>
>Thank you,
>Brian
>
>--
>TriLUG mailing list        : http://www.trilug.org/mailman/listinfo/trilug
>TriLUG FAQ  : http://www.trilug.org/wiki/Frequently_Asked_Questions




More information about the TriLUG mailing list