www.webdeveloper.com
Results 1 to 6 of 6

Thread: insert <option> to <select> on IE

Hybrid View

  1. #1
    Join Date
    Apr 2005
    Posts
    210

    Talking insert <option> to <select> on IE

    Code:
    //meSel is an object of <select>
    mySel.innerHTML =  "<option value='name'>name</option>";
    Code above failed on IE and is OK on FireFox.

    Do you have idea to insert <option> to <select> for IE by javascript?

    Thanks.

    .

  2. #2
    Join Date
    Mar 2011
    Posts
    1,108
    I suspect that your variable mySel is obtaining its reference to the <select> tag in a way that IE doesn't support. But it's impossible to tell from the single line you show. Post the rest of your code.
    Rick Trethewey
    Rainbo Design

  3. #3
    Join Date
    Apr 2005
    Posts
    210
    var mySel = document.getElementById('my-select');

  4. #4
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,252
    See this page to change select content in the fly with the Option() constructor which supports four parameters, the later two optional :
    new Option(text, value, defaultSelected, selected)

  5. #5
    Join Date
    Nov 2010
    Posts
    978
    Internet Explorer doesn't allow innerHTML to be used to update parts of elements of the page - such as table, select and probably anything else where the element uses more than one tag. See 007Julien's suggestion for how to properly insert an option

  6. #6
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,755
    You can also use the Native DOM:
    Code:
    var option = document.createElement("option");
    option.value = "foo";
    option.appendChild(document.createTextNode("Label"));
    document.getElementById('my-select').appendChild(option);

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