My select list is called dropListBuilding
. The following code does not seem to work:
for (var i = 0; i < buildings.length; i++) {
var val = buildings[i];
var text = buildings[i];
alert("value of builing at: " + i.toString() + " is: " + val);
$("#dropListBuilding").addOption(val, text, false);
}
This line dies:
$("#dropListBuilding").addOption(val, text, false);
What is the right to add items to the drop down in jQuery? I have tested without that line and the buildings variable does have my data element.
Don't make your code so complicated. It can be done simply as below by using a foreach-like iterator:
If you do not want to rely on the 3.5 kB plugin for jQuery or do not want to construct the HTML string while escapping reserved HTML characters, here is a simple way that works:
For me this one worked
Your code fails because you are executing a method (addOption) on the jQuery object (and this object does not support the method)
You can use the standard Javascript function like this:
This is working fine, try out this.
Doing it this way has always worked for me, I hope this helps.