?
Solved

Dynamically create a select element and add options to

Posted on 2005-03-03
2
Medium Priority
?
6,431 Views
Last Modified: 2008-03-17
I know how to dynamically add a select element to a form like so.
function addselect(form)
{
 iteration = iteration + 1
var boldtype = document.createElement('Select');
     boldtype.setAttribute('name', 'bold' + iteration);
    form.appendChild(boldtype);
}

But, I cant figure out how to add options to that select.  I have tried to grab that select box like so.
boldopt = form.elements['bold'+iteration];
boldopt[0] = new Option("NO', 'NO');
boldopt[1] = new Option("YES', 'YES');

But I get an undefined on boldopt = form.elements['bold'+iteration].

Is there another way to be able to add options to this newly created select element?
0
Comment
Question by:BenSwitzer
2 Comments
 
LVL 32

Accepted Solution

by:
Batalf earned 500 total points
ID: 13449137
boldtype.options[boldtype.options.length] = new Option('No','No');
0
 

Author Comment

by:BenSwitzer
ID: 13449178
darn that was easier than I thought. maybe I should have thought about it more.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question