Jump to content

Append drop down options string via javascript


Master81

Recommended Posts

Hi

 

Right I'm using ajax and php to dynamically populate my drop down list. All is working except one thing. I am trying to send the <option> tags (in an array) by echoing this out to the javascript file.

 

Now I know in javascript I can create new options by using the createElement option but how do I tell javascript that I want to basically append the <option> tags into the droplist?

 

If anyone has any thoughts on how I can do this, that would be great. Thanks.

I fought that for the longest time and then i found the "new Option()" way

so, I just bring back the option values in the xml and I clear out the current, and refill it.

you can do it other ways, like just doin the new Option()

 

here is code I use all the time (cross browsers)

var lSelectObj = document.getElementById('dropdown');
lSelectObj.options.length = 0
for (j=0;j<x.length;j++)
{
   vNewValues = optionVal[j];
	   vNewText = optionText[j]
           lSelectObj.options[j] = new Option(vNewText,vNewValues);
}

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.