0

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 ?
Sydney

2
Contributors
4
Replies
6
Views
6 Years
Discussion Span
Last Post by Sydney123
0

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

    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_"+following+"\"))!='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>

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

Edited by mike_2000_17: Fixed formatting

0

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

0

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]);
nOption.appendChild(nData);
currList.appendChild(nOption);
}
}
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 >

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.