Results 1 to 4 of 4

Thread: Why this not working

  1. #1
    Join Date
    Nov 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Why this not working

    Hi,

    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;
    alert(comboid.options.length);
    ====================

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


    Please help me to solve this ...(:

  2. #2
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote 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

  3. #3
    Join Date
    Nov 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

    I tried, with your code, but same error . Any other suggestions,please (:

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    This should have fixed it. Can you post the code you're using now, with Mike's modifications in?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •