Concatenate dynamic variable names

S

SABmore

I have a table that I populate with an array using ASP. As each row is
created, the form object names are appended a numeric, such as:
i = 1
<select name="select<%=i%>">
...
...
...
i = i+1
next

I then pass "i" to a javascript function, so that I can access the
values of each form object. I can't figure out how to properly
concatenate the "i" and still allow access to the value in the form
object. Currently I have:

var ps = 'platSymbol' + I;
alert(ps)
var sel = 'document.frmUpdPlatGrp.' + ps + '.value'
alert(sel)

I know I'm wrong, as this comes back as a complete string. Ultimately
I want to have something like this:

var s = document.frmUpdPlatGrp.platSymbol2.value - so that I can
actually get the value.

Can anyone help me out? Thanks in advance!
 
S

SABmore

I figured out my first question by using "eval", but now that I have
the value, I need to assign it to another dynamic form object for
holding, such as:

var ps = 'platSymbol' + I;
var sel = 'document.frmUpdPlatGrp.' + ps + '.value'
var val = eval(sel)

var ps2 = 'symbolId_changed' + I;
var hld = 'document.frmUpdPlatGrp.' + ps2 + '.value' = val

I then want to be able to access the form object like:
alert (document.formUpdPlatGrp.formObject2.value)
so that I can pass it thru my ASP page. Thanks!
 
M

Michael Winter

I figured out my first question by using "eval", [...]

Sorry, but had you read the group FAQ, you'd have found that the answer
is /not/ the global eval function.
var ps = 'platSymbol' + I;
var sel = 'document.frmUpdPlatGrp.' + ps + '.value'
var val = eval(sel)

var ps2 = 'symbolId_changed' + I;
var hld = 'document.frmUpdPlatGrp.' + ps2 + '.value' = val

var elem = document.forms.frmUpdPlatGrp.elements;

elem['symbolId_changed' + I].value = elem['platSymbol' + I].value;

[snip]

Hope that helps,
Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top