
Originally Posted by
eric_2005
var rowid = 1;
var comboid="document.forms[0].row_" +rowid;
At this point, the value of comboid will be:
  document.forms[0].row_1
However, it is a string value.
alert(comboid.options.length);
When the property access occurs with this function call, the string value will be temporarily converted to a String object, and the interpreter will attempt to find an options property. Strings do not have such a property (by default), so that part of the expression will evaluate to undefined. Trying to get a property from an undefined value results in an error.
What you should do is use bracket notation to construct the property name:
Code:
document.forms[0].elements['row_' + rowid].options.length
The string concatenation you can see above will create the string value, 'row_1', the name of the property you want.
The above is equivalent to:
Code:
document.forms[0].elements.row_1.options.length
but achieved dynamically.
Mike
Bookmarks