By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,381 Members | 1,626 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,381 IT Pros & Developers. It's quick & easy.

Help select

P: n/a
Hello,
I have definited two select: main, secondary

main = 0, 1, 2

secondaryA = "a", "b", "c"
secondaryB = "1", "2", "3"
secondaryC = "5", "6", "15", "25"

i want that, if i check from first select (main) the value 0, in secondary
select, will be displayed the value from secondaryA; if i set value 1, in
secondaty, will be displayed: secondaryB etc etc... shortly:

select 1 select 2
main(1) ==> secondaryA
main(2) ==> secondaryB
main(3) ==> secondaryC
who help me, for solve this problem?
thanks you, cooper.
PS: Sorry for my english
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Something like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<script language="JavaScript" type="text/javascript">
<!--
secondaryA = new Array("a", "b", "c");
secondaryB = new Array("1", "2", "3");
secondaryC = new Array("5", "6", "15", "25");

function main_changed(){
var obj = document.getElementById("main");
var selectedValue = obj.options[obj.options.selectedIndex].value;
var temp;
switch (selectedValue){
case "1":
temp = secondaryA;
break;
case "2":
temp = secondaryB;
break;
case "3":
temp = secondaryC;
break;
}
displaySecondary(temp);
}

function displaySecondary(whichArray){
var obj = document.getElementById("secondary");
deleteOptions(obj);
for (var i = 0; i<whichArray.length; i++){
var objOption = document.createElement("OPTION");
obj.appendChild(objOption);
objOption.value = i;
var newText = document.createTextNode(whichArray[i]);
objOption.appendChild(newText);
}
}

function deleteOptions(obj){
var l = obj.options.length;
for (var i=0; i<l; i++){
obj.options[0].removeNode(true);
}
}

//-->
</script>
</head>

<body>
<select id="main" onchange="main_changed();">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<select id="secondary"></select>
<script language="JavaScript" type="text/javascript">
<!--
displaySecondary(secondaryA);
//-->
</script>

</body>
</html>
"Cooper" <co****@blueware.it> wrote in message
news:U1**********************@news1.tin.it...
Hello,
I have definited two select: main, secondary

main = 0, 1, 2

secondaryA = "a", "b", "c"
secondaryB = "1", "2", "3"
secondaryC = "5", "6", "15", "25"

i want that, if i check from first select (main) the value 0, in secondary
select, will be displayed the value from secondaryA; if i set value 1, in
secondaty, will be displayed: secondaryB etc etc... shortly:

select 1 select 2
main(1) ==> secondaryA
main(2) ==> secondaryB
main(3) ==> secondaryC
who help me, for solve this problem?
thanks you, cooper.
PS: Sorry for my english

Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.