Click to See Complete Forum and Search --> : referring to dynamically named form elements


BananaQuaalude
08-09-2003, 12:05 PM
Hello,

I'm wondering if this is even possible- can you refer to a dynamically named form element (a text box) and assign a value to it?

Here's the element:

<input type="text" name="txt<%=RowData%>" value="">

RowData is going to equal 100, 101, 102, etc. - I won't know how far the list goes.

And what I need to do is refer to each one of those textboxes in a select's onChange event:

function changeIt(RowData){
document.frmData.txt[RowData].value = "[another value]"
}

I can't find a way to substitute the name of the textbox (keep getting 'object required' errors) because it doesn't recognize anything by that name.

Anyone?

AdamGundry
08-09-2003, 12:36 PM
Try this:
eval('document.frmData.txt' + RowData + '.value = "[another value]"');

Adam

BananaQuaalude
08-10-2003, 04:45 PM
That works.

I'm still a JavaScript novice. This will be very helpful in a lot of cases!

thanks!