Hello there

I have a script for creating 3 dependant drop down menu
Selection A in 1st drop Down returns
Selection B in 2nd drop Down which returns
Selection C in 3rd and final drop down

To C I would like to attach a string of 3 value ( prices )
I was thinking of using the array

var A_B_C = new Array(45, 275, 400);

but I am not to sure how to link this function to the code and how to return the price in 3 different box ? Can someone help ?

Recommended Answers

some code please

Jump to Post

All 4 Replies

some code please

Here is the code I am using

// 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", "--");

// third combo box

    data_1_1_1 = new Option("111", "*");
    data_1_2_1 = new Option("121", "*");
    data_2_1_1 = new Option("211", "**");

// fourth combo box

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

// other parameters



function change(currentbox) {
    numb = currentbox.id.split("_");
    currentbox = numb[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)

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

    while ((eval("typeof(document.getElementById(\"combo_"+i+"\"))!='undefined'")) &&
           (document.getElementById("combo_"+i)!=null)) {
           if (i==currentbox) break;

// filling the "son" combo (if exists)


    if ((eval("typeof(document.getElementById(\"combo_"+following+"\"))!='undefined'")) &&
       (document.getElementById("combo_"+following)!=null)) {
       son = document.getElementById("combo_"+following);
       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)")
                 eval("son.options[0]=new Option(displaywhennotempty,valuewhennotempty)")
              eval("son.options["+i+"]=new Option("+stringa+i+".text,"+stringa+i+".value)")
       while (cstatus[i]!=null) {
       return combostatus;


<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 name="combo1" id="combo_1" onChange="change(this)" style="width:200px;">
    <option value="value1">  </option>
<select name="combo2" id="combo_2" onChange="change(this);" style="width:200px;">
    <option value="value1">  </option>
<select name="combo3" id="combo_3" onChange="change(this);" style="width:200px;">
    <option value="value1">  </option>



Sorry dude...the code you pasted is horrible...no indentation
Its hard to understand this code...please paste indented code with proper code tags.

Apology about this, I have used a similar function code that seems to be less messy, does this help ?

< script type = "text/javascript" >
var categories =[];
categories["startList"] =["A", "B"]
categories["A"] =["A1", "A2", "A3"];
categories["B"] =["B1", "B2", "B3"];
categories["A1"] =["A11", "A12", "A13", "A14"];
categories["A2"] =["A21", "A22", "A23", "A24"];
categories["A3"] =["A31", "A32", "A33", "A34"];
categories["B1"] =["B11", "B12", "B13"];
categories["B2"] =["B21", "B22", "B23", "B24"];
categories["B3"] =["B31", "B32", "B33", "B34"];

var nLists = 3; // number of select lists in the set
function fillSelect(currCat, currList)
var step = Number(currList.name.replace(/D / g, ""));
for (i = step; i < nLists + 1; i++) {
document.forms.length = 1;
document.forms.selectedIndex = 0;
var nCat = categories[currCat];
for (each in nCat) {
var nOption = document.createElement('option');
var nData = document.createTextNode(nCat[each]);
nOption.setAttribute('value', nCat[each]);
function getValue(L3, L2, L1)
alert("Your selection was:- n" + L1 + "n" + L2 + "n" + L3);
function init()
{ fillSelect('startList', document.forms)

navigator.appName == "Microsoft Internet Explorer" ? attachEvent('onload', init, false) : addEventListener('load', init, false);
</script >

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.