Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    setting selected with createElement("option")

    I´m trying to create a dropdown menu through createElement, browser is IE.
    The problem is setting one of the options as "selected".

    So far I have:
    options = editor.config[txt];
    el = document.createElement("select");

    for (var i in options) {
    var op = document.createElement("option");
    op.appendChild(document.createTextNode(i));
    op.value = options[i];
    el.appendChild(op);
    }

    I get my dropdown menu, but how do I set selected?
    I´ve tried
    op.selected = true
    without success.
    Thanks for any help on this.

    -moradri-

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    op.selected = true works for me.

    If you execute it inside the for-loop, the last element will be selected if the combo box is not set as multiple. You have to execute it only once if you want the correct option to be selected.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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