Master81 Posted December 6, 2007 Share Posted December 6, 2007 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. Quote Link to comment Share on other sites More sharing options...
BenInBlack Posted December 6, 2007 Share Posted December 6, 2007 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); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.