www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] insert arrays into new option list

  1. #1
    Join Date
    Mar 2007
    Posts
    31

    resolved [RESOLVED] insert arrays into new option list

    I'm creating a new option list depending on the option chosen in another. I'm using a switch to assess value of the selected index, then using a case statement assign the appropriate values to an array. This is what I have.
    Code:
    var element = [[1,'Old Man','Old Man'],[2,'Old Dog,'Old Dog']];
    var id = document.getElementById('selectname');
    var Opt = id.createElement('Option');
    id.options.add(Opt);
    var id = Opt.id;
    var value = Opt.value;
    var text = Opt.text;
    insertOption(id,value,text);
    I placed an alert after
    Code:
    var id = document.getElementById('selectname');
    an it executes. I then placed the alert after
    Code:
    var Opt = id.createElement('Option');
    but it won't execute. Can't figure out why? Any help appreicated.

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    var element = [[1,'Old Man','Old Man'],[2,'Old Dog','Old Dog']];
    var id = document.getElementById('selectname');
    var Opt = document.createElement('Option');
    Opt.value = element[0][1];
    Opt.text = element[0][2];
    id.options.add(Opt);

  3. #3
    Join Date
    Mar 2007
    Posts
    31
    Thanks Fang. Got it working!.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles