?
Solved

Dynamically create a select element and add options to

Posted on 2005-03-03
2
Medium Priority
?
6,426 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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

765 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