Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Add items to a drop down control at run time

Posted on 2003-11-12
8
Medium Priority
?
838 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
7 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 1000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

877 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