Solved

Add items to select box dynamically using VBScript

Posted on 2004-03-20
4
3,222 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
  • 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now