Solved

Add items to select box dynamically using VBScript

Posted on 2004-03-20
4
3,361 Views
Last Modified: 2012-05-04
In Feb of this year.  Timbo87 gave a very short but very effective solution for adding items to a select box using JavaScript:

selectBox.length++
selectBox[selectBox.length-1].text = "new item"

I need to know what the equivalent VBScript code would be.  Or, if there really isn't an equivalant code using VBScript, perhaps someone can tell  me if there is a way to easily pass variables created/assigned  in VBScript  to JavaScript.
 
0
Comment
Question by:acaraciolo
[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
4 Comments
 
LVL 10

Expert Comment

by:D_M_D
ID: 10641689
I got it to add a space for the item, but just not the text.  I need to look somemore.

<html>
<head>
<script language="vbscript">

Function AddItem(form)
dim itemSel, intItems
      
    itemSel = form.newitem.value
    intItems = form.sel1.length
    form.sel1.length = intItems + 1
   

end function

</script>
</head>
<body>
<form name="frmAdd">
<input type="text" value="" name="newitem">
<input type="button" name="abtn" value="add" Onclick="AddItem(frmAdd)">
<br>
<select name="sel1">
<option value="">Value1</option>
<option value="">Value2</option>
<option value="">Value3</option>
</select>
</form>
</body>
</html>

--------
D_M_D
0
 
LVL 12

Accepted Solution

by:
venkateshwarr earned 500 total points
ID: 10641904

This should help you....

<form name="test">

<select name="state" size="1">
  <option value="" selected></option>
  <option value="v1">v1</option>
  <option value="v2">v2</option>
  <option value="v3">v3</option>
</select>

<SCRIPT language = "VBScript">
    function additem()
      Set objOpt = document.CreateElement("OPTION")
      objOpt.Value = 1                        
      objOpt.Text = "v4"
      document.test.state.add objOpt
      Set objOpt = Nothing
    end function
</SCRIPT>

<input type=button value=add onclick="additem()">

</form>
0
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10641915

In your case, it should be..

    Set objOpt = document.CreateElement("OPTION")
    objOpt.Value =  "new item"
    objOpt.Text =  "new item"
    selectBox.add objOpt

venkat
0
 

Author Comment

by:acaraciolo
ID: 10642391
Great job venkateshwarr, that was exactly what I needed....  Thanks
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

717 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