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?