Solved

Add items to a drop down control at run time

Posted on 2003-11-12
8
750 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
8 Comments
 
LVL 3

Expert Comment

by:monvelasquez
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:ussharma
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 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

14 Experts available now in Live!

Get 1:1 Help Now