Select help please

B

Boyd Reilly

I'm pretty new to this stuff, so any help is welcome.

I have a select list as follows:
<select name= "CHDRUGTYPE">
<option value="1">Beer</option>
<option value="2">Wine</option>
<option value="3">Hard Liquor</option>
<option value="4">Illegal Drugs</option>
</select>
On that same page I have another select list. However, I want this list to
be refelective of what is chosen in the first list. Thus, if Option1 is
chosen I want the second list to be:

<select name= "CHDRUG">
<option value="1">Becks</option>
<option value="2">Sam Adams</option>
</select>

If Option 2 is chosen I want the second list to be:
<select name= "CHDRUG">
<option value="1">Thunderbird</option>
<option value="2">Mad Dog</option>
</select>

I don't know how to change the second list after the first list is chosen.

As said, I'm pretty new to this stuff, so any help is more than welcome.

Thanks for the help.

Boyd
 
L

Leif K-Brooks

Boyd said:
On that same page I have another select list. However, I want this list to
be refelective of what is chosen in the first list.

Have the second list on a server-generated page which changes it.
 
B

Boyd Reilly

I appreciate the help, Leif, but you are talking over my head here. Keep in
ming,I need everything to be on the same page. If you could, can you post
codeof what needs to be done.

TIA.

Boyd
 
L

Leif K-Brooks

Boyd said:
I appreciate the help, Leif, but you are talking over my head here. Keep in
ming,I need everything to be on the same page. If you could, can you post
codeof what needs to be done.

In PHP:
if (empty($_POST['CHDRUGTYPE'])) {
firstform();
}
switch ($_POST['CHDRUGTYPE']) {
case 1:
# Display the select list for option 1
break;
case 2:
# Select list for option 2
break;
default:
firstform();
}
function firstform() {
// Display a form with the first select list
}
 
B

Boyd Reilly

I appreciate your patience with me. But, when I add that code it
doesnothing but to add more unwanted tet to the screen. Please try this and
tell me where I go wrong:

<select name= "CHDRUGTYPE">
<option value="1">Beer</option>
<option value="2">Wine</option>
<option value="3">Hard Liquor</option>
<option value="4">Illegal Drugs</option>
</select>

<select name= "CHDRUG">
<option value="1">Becks</option>
<option value="2">Sam Adams</option>
</select>


<select name= "CHDRUG">
<option value="1">Thunderbird</option>
<option value="2">Mad Dog</option>
</select>

if (empty($_POST['CHDRUGTYPE'])) {firstform()} switch ($_POST['CHDRUGTYPE'])
{case 1: # Display the select list for option 1 break; case 2: # Select list
for option 2 break; default: firstform(); } function firstform() {// Display
a form with the first select list}

Boyd
Leif K-Brooks said:
Boyd said:
I appreciate the help, Leif, but you are talking over my head here. Keep in
ming,I need everything to be on the same page. If you could, can you post
codeof what needs to be done.

In PHP:
if (empty($_POST['CHDRUGTYPE'])) {
firstform();
}
switch ($_POST['CHDRUGTYPE']) {
case 1:
# Display the select list for option 1
break;
case 2:
# Select list for option 2
break;
default:
firstform();
}
function firstform() {
// Display a form with the first select list
}
 
F

Fredo Vincentis

Boyd Reilly said:
I appreciate your patience with me. But, when I add that code it
doesnothing but to add more unwanted tet to the screen.

Leif's code is the best solution to your problem, but it requires your
website to run on a server that supports server-side scripting. You get the
extra text on the screen, because you are putting PHP code into a HTML file.

If you have got lots of different options that are going into the SELECT
fields, you might be doing good in learning a bit of PHP in addition to the
HTML you already know. But if you have only got one or two selection boxes
with a few entries each, this link might help you to achieve what you want:

http://www.acmesoffware.com/acme/ExamplesJS/jsExm_CreateSelects.asp

It is an intro on how to dynamically populate select boxes using javascript.
All you have to do is copy and paste the code into your HTML document (the
form code into the <body>, the javascript into the <head>) and make the
appropriate changes to the entries.

In order to change the javascript in the link above, all you have to do is
change the value of the <option> tags to whatever you want. E.g. Beer, Wine,
Hard Liquor, etc. Then in the javascript, you will notice that there are
lines that currently say:

case "Item1" :

and

case "Item2" :

Change those lines to what you wrote into your option values. For example:

case "Beer" :

case "Wine" :

etc.

Finally, enter the new options you want in your selection box under each of
the "cases". Currently they have got label A1, label A2, etc.

If you have difficulties with it, let me know.
 
F

Fredo Vincentis

Leif K-Brooks said:
Oh &deity;, not one of those! How on earth am I supposed to fill out
your form without JavaScript? Since the OP was using a form, some type
of server-side scripting must be available. Use that.

You seem to forget that it takes a bit to learn server-side scripting. Not
everybody has got the time or the technical skill to learn ASP or PHP. As I
said: I agree it's the right solution, but javascript may be the way to go
for Boyd (depends on what his site is trying to achieve).
 
D

David Dorward

Fredo said:
You seem to forget that it takes a bit to learn server-side scripting.

It also takes a bit to learn client-side scripting. One is dependable and
useful for essential functionality, one is undependable and useful for
optional extras.
Not everybody has got the time or the technical skill to learn ASP or PHP.

or JavaScript.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top