Click to See Complete Forum and Search --> : Reading dynamically named form element's value


BananaQuaalude
01-13-2004, 10:02 AM
I need to read data from a dynamically named form element. Sometimes the element will start with the word "New" and sometimes it will be "Upd."

I'm using the following function to test which one exists:

function isObject(element) {
return (typeof element == 'object');
}

Why will the following not work? I get an 'Expected Identifier' error.

if (isObject( document.frmData.["New-" + arr1[h] + "-" + arr2[h] ] ) == true) {
alert( document.frmData.["New-" + arr1[h] + "-" + arr2[h] ].value )
}

The arrays hold the rest of the dynamic name. I've checked the value of

["New-" + arr1[h] + "-" + arr2[h] ]

with an alert box--it is the correct element name. Why won't this work?

fredmv
01-13-2004, 10:09 AM
Consider the following piece of code:document.frmData.["New-" + arr1[h] + "-" + arr2[h] ]Try removing that dot.

BananaQuaalude
01-13-2004, 10:16 AM
And that will do it!

Thanks for being the extra set of eyes- what a difference that makes sometimes!