View Full Version : Why this not working

11-18-2005, 02:53 AM

I got multiple rows with same COMBOX BOX ,differentiated with its row ID.

I am able to get the row id no. But, with rowid when i
try to get the selection box element length, it fails .

By doing directly like this, i am getting value.
----> alert(document.forms[0].rowid_1.options.length);

But with this one gives error,


var x = 1;
var rowid = 1;
var comboid="document.forms[0].row_" +rowid;

Error : 'options.length' is null or not an object.

Please help me to solve this ...(:

11-18-2005, 05:43 PM
var rowid = 1;
var comboid="document.forms[0].row_" +rowid;At this point, the value of comboid will be:


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:

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:

but achieved dynamically.


11-18-2005, 07:48 PM
I tried, with your code, but same error . Any other suggestions,please (:

11-18-2005, 08:07 PM
This should have fixed it. Can you post the code you're using now, with Mike's modifications in?