?
Solved

Add items to select box dynamically using VBScript

Posted on 2004-03-20
4
Medium Priority
?
3,431 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 2000 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
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…
Suggested Courses

752 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