Dynamically Adding OPTIONS to SELECT

Illustrates how to add OPTIONS to a SELECT using client-side JavaScript


Feel the need to add to the options that are available in a <SELECT> tag from the browser? The code below contains an illustration of the basic technique.

Dim anOption
Set anOption = document.createElement("OPTION")
document.form1.select1.options.add anOption
anOption.innerText = "Two"
anOption.Value = "2"


 Want to do the same thing, but in JavaScript. Try the following    

var anOption = document.createElement("OPTION")
document.form1.select1.options.add(anOption)
anOption.innerText = "Two"
anOption.Value = "2"


Almost too easy, isn't it.    
 

You might also like...

Comments

Bruce Johnson I am the owner of a small application development consulting company that specialized in the design and implementation of Internet-based applications. While there are others who can make a web site...

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.” - Antoine de Saint Exupéry