473,416 Members | 1,564 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Multiple dynamic combo boxes

<html>
<head>
<script language="JavaScript">
<!--

/*
*** Multiple dynamic combo boxes
*** by Mirko Elviro, 9 Mar 2005
***
***Please do not remove this comment
*/

// This script supports an unlimited number of linked combo boxed
// Their id must be "combo_0", "combo_1", "combo_2" etc.
// Here you have to put the data that will fill the combo boxes
// ie. data_2_1 will be the first option in the second combo box
// when the first combo box has the second option selected
// first combo box

data_1 = new Option("1", "$");
data_2 = new Option("2", "$$");

// second combo box

data_1_1 = new Option("11", "-");
data_1_2 = new Option("12", "-");
data_2_1 = new Option("21", "--");
data_2_2 = new Option("22", "--");
data_2_3 = new Option("23", "--");
data_2_4 = new Option("24", "--");
data_2_5 = new Option("25", "--");

// third combo box

data_1_1_1 = new Option("111", "*");
data_1_1_2 = new Option("112", "*");
data_1_1_3 = new Option("113", "*");
data_1_2_1 = new Option("121", "*");
data_1_2_2 = new Option("122", "*");
data_1_2_3 = new Option("123", "*");
data_1_2_4 = new Option("124", "*");
data_2_1_1 = new Option("211", "**");
data_2_1_2 = new Option("212", "**");
data_2_2_1 = new Option("221", "**");
data_2_2_2 = new Option("222", "**");
data_2_3_1 = new Option("231", "***");
data_2_3_2 = new Option("232", "***");

// fourth combo box

data_2_2_1_1 = new Option("2211","%")
data_2_2_1_2 = new Option("2212","%%")

// other parameters

displaywhenempty=""
valuewhenempty=-1

displaywhennotempty="-select-"
valuewhennotempty=0
function change(currentbox) {
numb = currentbox.id.split("_");
currentbox = numb[1];

i=parseInt(currentbox)+1

// I empty all combo boxes following the current one

while
((eval("typeof(document.getElementById(\"combo_"+i +"\"))!='undefined'"))
&&
(document.getElementById("combo_"+i)!=null)) {
son = document.getElementById("combo_"+i);
// I empty all options except the first one (it isn't allowed)
for (m=son.options.length-1;m>0;m--) son.options[m]=null;
// I reset the first option
son.options[0]=new Option(displaywhenempty,valuewhenempty)
i=i+1
}
// now I create the string with the "base" name ("stringa"), ie.
"data_1_0"
// to which I'll add _0,_1,_2,_3 etc to obtain the name of the combo
box to fill

stringa='data'
i=0
while
((eval("typeof(document.getElementById(\"combo_"+i +"\"))!='undefined'"))
&&
(document.getElementById("combo_"+i)!=null)) {

eval("stringa=stringa+'_'+document.getElementById( \"combo_"+i+"\").selectedIndex")
if (i==currentbox) break;
i=i+1
}
// filling the "son" combo (if exists)

following=parseInt(currentbox)+1

if
((eval("typeof(document.getElementById(\"combo_"+f ollowing+"\"))!='undefined'"))
&&
(document.getElementById("combo_"+following)!=null )) {
son = document.getElementById("combo_"+following);
stringa=stringa+"_"
i=0
while ((eval("typeof("+stringa+i+")!='undefined'")) || (i==0)) {

// if there are no options, I empty the first option of the
"son" combo
// otherwise I put "-select-" in it

if ((i==0) && eval("typeof("+stringa+"0)=='undefined'"))
if (eval("typeof("+stringa+"1)=='undefined'"))
eval("son.options[0]=new
Option(displaywhenempty,valuewhenempty)")
else
eval("son.options[0]=new
Option(displaywhennotempty,valuewhennotempty)")
else
eval("son.options["+i+"]=new
Option("+stringa+i+".text,"+stringa+i+".value)")
i=i+1
}
//son.focus()
i=1
combostatus=''
cstatus=stringa.split("_")
while (cstatus[i]!=null) {
combostatus=combostatus+cstatus[i]
i=i+1
}
return combostatus;
}
}

//-->
</script>
<title>Multiple dynamic combo boxes - by Elviro Mirko</title>
</head>
<body>
<form>
<select name="combo0" id="combo_0" onChange="change(this);"
style="width:200px;">
<option value="value1">-select-</option>
<option value="value2">1</option>
<option value="value3">2</option>
</select>
<BR><BR>
<select name="combo1" id="combo_1" onChange="change(this)"
style="width:200px;">
<option value="value1"> </option>
</select>
<BR><BR>
<select name="combo2" id="combo_2" onChange="change(this);"
style="width:200px;">
<option value="value1"> </option>
</select>
<BR><BR>
<select name="combo3" id="combo_3" onChange="change(this);"
style="width:200px;">
<option value="value1"> </option>
</select>

</form>
</body>
</html>

Jul 23 '05 #1
3 4275
vg*******@libero.it wrote:
<html>
<head>
<script language="JavaScript">
<!--

/*
*** Multiple dynamic combo boxes
*** by Mirko Elviro, 9 Mar 2005
***
***Please do not remove this comment
*/


LOL where is your problem?
NRN
Jul 23 '05 #2
I guess you can further improve on the function change(). It uses eval
quite a lot and i think you can pass more arguments to it, have
data[1][2] instead of data_1_2, etc. But what is the _problem_??

Jul 23 '05 #3
c.**********@gmail.com wrote:
I guess you can further improve on the function change(). It uses eval
quite a lot and i think you can pass more arguments to it, have
data[1][2] instead of data_1_2, etc. But what is the _problem_??


I see 2 problems:

Not quoting previous posting?
The script?

Mick
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: mr_burns | last post by:
hi, is it possible to change the contents of a combo box when the contents of another are changed. for example, if i had a combo box called garments containing shirts, trousers and hats, when...
0
by: Duncan Spence | last post by:
Hi all, I'm sure I'm doing something silly here, but can't see it! I'm creating a series of combo boxes on a Windows Form in VB.NET. The lists of all of the comboboxes are identical and are...
2
by: taras.di | last post by:
Hi everyone, I've been reading up on how to create a drop down box who's context is dynamically produced based on the value of a previous select box. I've read a lot about some of the browsers...
1
by: Shawn Yates | last post by:
It has been a while since I have done anything on MS Access and I seem to be a bit rusty. I hope someone could help me solve my issue. I have a form that has multiple combo boxes on it. Each box...
0
by: arsenal69 | last post by:
Hi to all... last time i gave an incomplete description of the real problem.. even though i got help.. and i am very thankful for that any ways heres what i really need help on 2 combo boxes.......
2
by: Dave | last post by:
I have 3 tables of information feeding into 4 combo boxes on my main form (DR Form). I have as many list boxes (acting as text boxes) as there are fields in each one of the 3 tables. Once...
4
by: pbsree | last post by:
how to generate multiple dynamic text boxes
1
by: bkholloway | last post by:
hello...first time here...have an access 07 db and need to have multiple dependent combo boxes. I have a little experience using expression builder but not VBA...basically need to limit choices in...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.