Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Box, Variable 1

Status
Not open for further replies.

lollorosso

Technical User
Aug 16, 2001
3
SG
Hello,

I have a problem with combo boxes on a html page:

This code delievers a combo box:

<p><b>&nbspExample&nbsp; <select id=&quot;cbxExample&quot;>
<option>&nbsp;</option>

<script language=&quot;VBScript&quot;>

set opt = document.createElement(&quot;Option&quot;)
opt.Text = &quot;test1&quot;
opt.Value = &quot;test1&quot;
cbxExample.options.add opt

I am very new to VBScribt and thus I have no idea how to
1) set a default value for the combo box
2) use the result of the user's choice (when having used the combo box)
3) Prevent the user from not choosing anything

If anybody knows how to help me it would be great!

Thanks

Jan
 
Hi

What you're using there is actually Javascript or JScript. You won't need any VBScript at all to make a combo box like that. This is plain html:
Code:
<form action=&quot;newPage.asp&quot;>
   <select id=&quot;cbxExample&quot;>
      <option value=10>OneChoice</option>
      <option
selected
Code:
 value=32>AnotherChoice</option>
      <option value=39>YetAnotherChoice</option>
   </select>
</form>
The word selected in the code above sets the default value, and is the answer to your question 1 and 3.

Using the result of the users choice can be done in several ways, depending on what you want to do.

Hope this helps,
Palooka
 
Hello Palooka, hello others,

thanks for this answer which is quite helpful for me.
I just have a little problem right now: I do not know how to address the result of the combo-box choice.

That is: I need to check what

cbxExample.value

contains. Unfortunately the above syntax does not work. How do I have to address cbxExample in order to make an If-Then statement possiple:

If cbxExample.XXX = Y then
.....

Thanks a lot

Jan
 
That depends on when you want to read the contents of the combo-box. If you want to read it right away, as soon as the user has made his choice, you would use something like the onChange Javascript event.
(If that is the case, check out )

If you want to collect several bits of information from combo boxes, input boxes, text areas, etc., you would want to use a Form, like in the example in my previous post. Inside this Form you also need a submit-button, which will redirect you to a page of your choice (newPage.asp in the example).

From this new page you have access to all the elements of the Form on the previous page. It is called a Form Collection. If you had a combobox like this:

Code:
   <select name=&quot;myCombo&quot;>

The way to get the selected value would be either of these two:
Code:
   value = Request.Form(&quot;myCombo&quot;)
   value = Request.Form.Item(1)

(As you've probably guessed, the number 1 is referring to the first object in the Form Collection.)

Hope this helps,
Palooka
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top