Solved

Add items to a drop down control at run time

Posted on 2003-11-12
8
806 Views
Last Modified: 2010-08-05
Hi all of you,

I am trying to add items to a drop down control at run time. Items will be added to it on clicking a button. I have associated a VBScript function to the button on it onClick event.
But unfortunately the add statement to the drop down control is not working. Please help.
My GO button declaration is like this
<.........GoButton........................ onClick = "loadAttributes()">
 
lstAttribute is the drop down list which should get loaded with some items.
 
SCRIPT Code section:

<SCRIPT language="VBScript">
sub loadAttributes()
 
lstAttribute.add "ABC",1                         (not working ERROR : Type Mismatch. I have also tried lstAttribute.addItem  “ABC”,1  . it is also not           working )
 
end sub
</SCRIPT>
 
please help out with the example.
 
0
Comment
Question by:ussharma
[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
8 Comments
 
LVL 3

Expert Comment

by:monvelasquez
ID: 9737218
if you wouldn't mind, i would rather do this in javascript. here's a sample..

--[CODE]----------------------------------------------------
<HTML>
<head>
<script language="javascript">
   function loadAttributes() {
     var newOp = new Option("Option 2",2);
     document.frm.lstAttribute.add(newOp);
   }
</script>

</head>
<body>

<form name="frm">
<select name="lstAttribute" size="10">
   <option value="1">Option 1
</select>

<input type="button" name="add" value="Add" onclick="loadAttributes()">

</form>
</bodY>
</HTML>
--[/CODE]---------------------------------------------------
0
 
LVL 3

Expert Comment

by:vijay7248
ID: 9737343
Usha,
R u going to do that in the server side or the client side..
If the values are fetched from DB, then I have another option.
Please clear this
0
 
LVL 3

Accepted Solution

by:
vijay7248 earned 250 total points
ID: 9737458
Try this. Cut and paste the below code run the page
<html>
<head>
<SCRIPT LANGUAGE="VBScript">
<!--
sub loadAttributes()
  Document.frmExercise4.cmbProducts.Additem "NEC MultiSync E1100"
  Document.frmExercise4.cmbProducts.Additem "NEC MultiSync P1150"
  Document.frmExercise4.cmbProducts.Additem "NEC MultiSync E750"
  msgbox ("loaded")
end sub
-->
</SCRIPT>
</head>
<body>
<FORM NAME="frmExercise4">
       <OBJECT ID="cmbProducts" WIDTH=159 HEIGHT=24
            CLASSID="CLSID:8BD21D30-EC42-11CE-9E0D-00AA006002F3">
          <PARAM NAME="DisplayStyle" VALUE="7">
          <PARAM NAME="Size" VALUE="4202;635">
          <PARAM NAME="FontHeight" VALUE="200">
          <PARAM NAME="MatchEntry" VALUE="1">
          <PARAM NAME="ShowDropButtonWhen" VALUE="2">
          <PARAM NAME="FontCharSet" VALUE="0">
          <PARAM NAME="FontPitchAndFamily" VALUE="2">
          <PARAM NAME="FontWeight" VALUE="0">
      </OBJECT>
<input type=button name=but1 onclick="loadAttributes()">
</form>
</body>
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ussharma
ID: 9737755
i need to access the values from the database in Oracle using ADODB connection. but the loading of the drop down list have to be done using VBScript. i have done the same in javascript. dont know why its not working
in VBScript (neither add nor addItem).  
0
 
LVL 2

Expert Comment

by:Sairam_S
ID: 9737835
Hi Sharma,

I read through your doubt and was trying to solve the problem in VBScript. I could not find any solution or reference for the same. I have developed a javascript version of the same code.. You can also include your VBScript functions in the same. i.e your additem code alone would refer to Javascript and other functions can refer to your VBScript Code

#Code Listing#

<html>
      <head>
            <title>Javascript List Populate</title>

            <style>
                  BODY { font-family: Verdana, Arial, Helvetia; font-size: 11px; }
            </style>
            
            <script language="javascript">
                  
                  function addItem()
                  {
                        var frm;
                        frm = document.listDemo;
                        if (frm.txtText.value != "" && frm.txtValue.value != "")
                        {
                              var newOption = new Option(frm.txtText.value, frm.txtValue.value);
                              frm.lstAttribute.options[frm.lstAttribute.length] = newOption;
                              frm.lstAttribute.value = frm.txtValue.value;
                        }
                        else
                        {
                              alert("Please enter the Text to be displayed and value");
                        }
                  }

            </script>

            <script language = "vbscript">
                                      'Write the other VBScript code here
            </script>

      </head>
      <body>
            <h3>List Box Demo :: Populate a new item </h3>
            <form name="listDemo">
                  <select name="lstAttribute">
                        <option value="1">One</option>
                        <option value="2">Two</option>
                  </select>
                  <br /><br /><b>Add a new item</b><br />
                  Item Text : <input type="text" name="txtText" size="30" /> Item Value <input type="text" name="txtValue" size="30" />
                  <br /><br />
                  <input type="button" name="btnAdd" value="Add the new item" onclick="javascript:addItem();" />
            </form>
      </body>
</html>
0
 
LVL 3

Expert Comment

by:vijay7248
ID: 9739172
If your loading populating the listbox with DB values...
Then here's some ASP code. Try this simple and compact method

Let's say ur query is 'qry' and u r storing the result set in 'rs'
Assuming Conn as your Connection Object
qry="select rec_id,first_name from tab1"
set rs=Conn.Execute(qry)  'You can also use Conn.Open here
Then the following code gives you a listbox

Response.Write "<select name='Listbox1'>" & _
   "<option selected value='All'>--All--</option>"
if not rs.eof then
   Response.Write("<option value='")
   Response.Write rs.getstring(,,"'>", _
             "</option><option value='", "-null-")
   Response.Write("'></option>")
end if
Response.write "</select>"

'The above code stores rec_id in the value of OPTIONS and first_name is displayed as the TEXT..
Try this it is very simple

For further reference regarding this code pls refer
http://www.4guysfromrolla.com/webtech/102600-1.shtml

'NOTE : This is a server-side code.
0
 
LVL 7

Expert Comment

by:vnvk
ID: 12064273
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
    Accept: vijay7248 {http:#9737458}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

vnvk
EE Cleanup Volunteer
0

Featured Post

[Webinar] Learn 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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

734 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