Computer and Internet » Programming » Javascript

ID #1004

Populate SELECT Tag with Dojo and CakePHP

At FireFox you can use

selectTag.innerHTML = textLoadedWithXHR

to populate a select input. Intenet Explorer doesn't support that feature! It's a bug as you can see in the Microsoft KB.

I used JSON support and Dojo to populate an existing select input with new options.

Check out the following Javascript code:


var sel = document.getElementById("selectTag");
//delete old entries
while (sel.length > 0)
sel.options[sel.length-1] = null;

for (var key in json)
{
var value = json[key];

var opt = new Option(value, key);

sel.options[sel.length] = opt;
}

Tags: -

Related entries:

Last update: 2006-10-20 18:58
Author: Christian Trummer
Revision: 1.0

Digg it! Print this record Send to a friend Show this as PDF file
Propose a translation for Propose a translation for
Please rate this entry:

Average rating: 2 out of 5 (2 Votes )

completely useless 1 2 3 4 5 most valuable

You cannot comment on this entry