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")

    Im 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?
    Ive 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
    10,962
    Thanks
    0
    Thanked 236 Times in 233 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.


  •  

    Posting Permissions

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