-
Hello!
I'm trying to create <option> tags dynamically. These get filled with content from an xml file --I know this part works. Its the creation of the actual <option> tags thats a problem. It does work on Firefox but on IE 7 it only gives me a long dropdown with no text values.
BTW, I'm using jQuery as well, although I don't think that matters.
Method 1:
Code:
var optn = document.createElement("option");
optn.innerHTML = $("name", this).text();
optn.value = $("id", this).text();
$("select#SchoolID").append(optn);
Method 2:
Code:
var optn = document.createElement("option");
optn.text = $("name", this).text();
optn.value = $("id", this).text();
$("select#SchoolID").append(optn);
Method 2:
Code:
var thetxt = $("name", this).text();
var thevalue = $("id", this).text();
var newoption = new Option(thetxt,thevalue, false);
$("select#SchoolID").append(newoption);
Thanks in advance! :)
-
What does $("name", this) do? Have you tried logging or alerting the value of thetxt?
-
To those who don't know jQuery, using the $("selector") syntax uses a CSS-like selector for the "selector". So $("#header") would select the element with the ID "header". The selected element can then be passed on to the next function.
The second param of the $ function is context... In other words, it only looks for elements within that context.
jQuery allows you to make elements on the fly, in a better manner. You can also use the $("element") syntax to generate elements. Like, you can do $("<option value="+value+">"+text+"</option>") and so on, changing variables as you see fit. Then you can simply appendTo it to the selection element.