Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Add items to select box dynamically using VBScript

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
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
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Suggested Courses

618 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