469,271 Members | 1,424 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Populating Selectbox

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..

Nov 16 '06 #1
1 1432
ASM
ev*******@gmail.com 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[i], 'Section '+val[i]);
son[son.length] = o;
}
}

<SELECT name="ddlAvailable">
<SELECT name="ddlAvailable" onchange="newSelect();">
<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>


--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Contact : http://stephane.moriaux.perso.wanadoo.fr/contact
ASM = Aimable Stéphane Moriaux = Amateur Sasseur Merdouilles
Nov 16 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Tole | last post: by
5 posts views Thread by bigbuddha | last post: by
7 posts views Thread by Erwin Moller | last post: by
3 posts views Thread by Stefan Richter | last post: by
4 posts views Thread by shankwheat | last post: by
4 posts views Thread by evanburen | last post: by
1 post views Thread by giloosh | last post: by
3 posts views Thread by =?iso-8859-1?q?Jesper_R=F8nn-Jensen?= | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.