Populating Selectbox

E

evanburen

I have 2 selectboxes and I want to change the values in the second
based on the first one. I found a few examples of this but none of
them quite do what I want. Could someone get me started on this or
point me to an example? Thanks

Box 1:

<SELECT name="ddlAvailable">
<option value="A,B,C,D,E">All Sections</option>
<OPTION VALUE = "A,B,C">A,B,C</Option>
<OPTION VALUE = "A">A</Option>
<OPTION VALUE = "D,E">D,E</Option>
<OPTION VALUE = "F">F</Option>
</SELECT>


Box 2:

If 'All Sections' is selected in ddlAvailable then

<SELECT name="ddlSelected">
<option value="A">Section A</option>
<option value="B">Section B</option>
<option value="C">Section C</option>
<option value="D">Section D</option>
<option value="E">Section E</option>
</SELECT>

If 'A,B,C' is selected in ddlAvailable then

<SELECT name="ddlSelected">
<option value="A">Section A</option>
<option value="B">Section B</option>
<option value="C">Section C</option>
</SELECT>

If 'A' is selected in ddlAvailable then

<SELECT name="ddlSelected">
<option value="A">Section A</option>
</SELECT>

etc..
 
A

ASM

(e-mail address removed) a écrit :
I have 2 selectboxes and I want to change the values in the second
based on the first one. I found a few examples of this but none of
them quite do what I want. Could someone get me started on this or
point me to an example? Thanks

function newSelect() {
// give here name (not id) of your form :
var f = document.forms['theForm'];
var dad = f.ddAvaiilable;
var son = f.ddlSelected;
var k = dad.selectedIndex;
var val = dad.options[k].value.split(',');
son.length = 0;
for(var i=0; i<val.length; i++)
{
var o = new Option(val, 'Section '+val);
son[son.length] = o;
}
}
 

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,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top