Select control question in Javascript

C

Carl Wu

Hi all,

I am newcomer in HTML, Javascript,

I want to create two select controls S1, S2.

There are 3 options: ALL, A, B in S1;

When select A in S1, It let you select A1, A2 in S2,

Where select B in S1, It let you select B1, B2 in S2;

When select ALL in S1, It let you select A1, A2, B1, B2 in S2

The default selection in S1 is ALL,

Can somebody give me some suggestion?

Thanks advance

Carl
 
T

Thomas 'PointedEars' Lahn

Carl said:
I want to create two select controls S1, S2.

<select name="S1">
</select>

<select name="S2">
There are 3 options: ALL, A, B in S1;

<select name="S1">
<option>ALL</option>
<option>A</option>
<option>B</option>
When select A in S1, It let you select A1, A2 in S2,

Where select B in S1, It let you select B1, B2 in S2;

When select ALL in S1, It let you select A1, A2, B1, B2 in S2

<script type="text/javascript" language="JavaScript">
<!--
function enableItems(o)
{
if (!o || !o.form || !o.form.elements)
return false;

var
o2 = o.form.elements['S2'],
a1 = o2.options[0],
a2 = o2.options[1],
b1 = o2.options[2],
b2 = o2.options[3];

if (o2 && a1 && typeof a1.disabled != "undefined")
{
switch (o.selectedIndex)
{
case 0: // ALL
a1.disabled = false;
if (a2)
a2.disabled = false;
if (b1)
b1.disabled = false;
if (b2)
b2.disabled = false;
break;

case 1: // A
a1.disabled = false;
if (a2)
a2.disabled = false;
break;

case 2: // B
if (b1)
b1.disabled = false;
if (b2)
b2.disabled = false;
}
}
}
//-->
</script>
<form action="...">
<select name="S1" onchange="enableItems(this)">
<option>ALL</option>
<option>A</option>
<option>B</option>
</select>

<select name="S2">
<option>A1</option>
<option>A2</option>
<option>B1</option>
<option>B2</option>
</select>
</form>

Untested.
The default selection in S1 is ALL,

It is the default because it is the first item.
Can somebody give me some suggestion?

See above. And before you post to a newsgroup the next time, you should get
a minimum clue of what you are doing (by reading documentations, FAQS aso.)
This is not a support forum but a discussion group.


PointedEars
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top