Jump to content

IE problem with <option> text using HTML DOM


Guest Webbo

Recommended Posts

I was going to create something as simple (at least I thought it was simple) as <select> with a bunch of options using HTML DOM. Everything works fine in Firefox, but in Internet Explorer - not so much. In IE the text of the option is not shown. The value works correct (I know that because I've created it as a menu and based on the value, you're taken to a specific page - and that works as intended) but the actual text of the option is not there (the line is empty). The way you create the option's text is...var THEOPTION = document.createElement("option");THEOPTION.value = "The value of the option.";THEOPTION.text = "The text of the option - the text that the user sees";...isn't it? :) My code for creating <select> with options below. (Code for button, listeners etc not included.)

function drawSelectmeny()     {      var pbpicsmenyp = document.getElementById("navigate_pbpics_p");      if(pbpicsmenyp)           {                  var pbpicsselect = document.createElement("select");            pbpicsselect.id = "navigate_pbpics";            pbpicsmenyp.appendChild(pbpicsselect);            var pbpicsoptgroup1 = document.createElement("optgroup");            pbpicsoptgroup1.label = "Season 1 screen caps";            pbpicsselect.appendChild(pbpicsoptgroup1);               var pbpicsog1op2 = document.createElement("option");               pbpicsog1op2.value = "102_allen";               pbpicsog1op2.text = "1.02 Allen";               pbpicsoptgroup1.appendChild(pbpicsog1op2);               var pbpicsog1op3 = document.createElement("option");               pbpicsog1op3.value = "103_cell_test";               pbpicsog1op3.text = "1.03 Cell Test";               pbpicsoptgroup1.appendChild(pbpicsog1op3);            /* More optgroups and options... */          };     };

Link to comment
Share on other sites

IE doesn't support "text" as far as I'm aware. Cross browser approaches include creating a text node, and changing it's nodeValue, OR (the more efficient and easier way) set the innerHTML property:

THEOPTION.innerHTML = "The text of the option - the text that the user sees";

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...