Hello,
I'm just reprogramming an existing Javascript und got to a problem.
Maybe anybody of yu know a solution to it.
With the existing Script (http://www.mattkruse.com/javascript/dynamicoptionlist/)
six optionlists should be filled dynamically with content and - if
you select an option - the content which isn't connected to the selection
should disappear from the other option lists.
At first the connected IDs are written into an array and saved temporarily
for each entry. But these connections are saved the wrong way.
Here is an extract of the script:
function DynamicOptionList_addOptions(dependentValue) {
var test = dependentValue;
var arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12,arg13,argA,argB,argC,argD,argE,argF,argG,argH,argI,argJ,argK,argL,argM;
var alle = 0;
var zaehlen = 0;
// count the number of the passed IDs
for (var f=1; test.indexOf('|') != -1; f++) {
var laenge = test.length;
var pos = test.indexOf('|');
zaehlen++;
var nummer = zaehlen+''; // convert number to string
// extract the IDs seperately
switch (nummer) {
case '1': arg1 = test.substring(0,pos);
break;
case '2': arg2 = test.substring(0,pos);
break;
case '3': arg3 = test.substring(0,pos);
break;
case '4': arg4 = test.substring(0,pos);
break;
case '5': arg5 = test.substring(0,pos);
break;
case '6': arg6 = test.substring(0,pos);
break;
default: break;
}
test = test.substring(pos+1,laenge);
}
// count the numbers of possibilities (2 to the power of f)
var anzahl = Math.pow(2,f);
var zaehlen2 = 0;
// and get the items of all possibilities
for (var g=1; g<=anzahl; g++) {
zaehlen2++;
nummer2 = zaehlen2+'';
if (arg1 != 0) {
if (nummer2 % 2 == 1) {argA=arg1;} else {argA=alle;}
dependentValue = argA
}
if (arg2 != 0) {
if (nummer2 % 4 <= 2) {argB=arg2;} else {argB=alle;}
dependentValue = argA + this.delimiter + argB
}
if (arg3 != 0) {
if (nummer2 % 8 <= 1) {argC=arg3;} else {argC=alle;}
dependentValue = argA + this.delimiter + argB + this.delimiter + argC
}
if (arg4 != 0) {
if (nummer2 % 16 <= 1) {argD=arg4;} else {argD=alle;}
dependentValue = argA + this.delimiter + argB + this.delimiter + argC + this.delimiter + argD
}
if (arg5 != 0) {
if (nummer2 % 32 <= 1) {argE=arg5;} else {argE=alle;}
dependentValue = argA + this.delimiter + argB + this.delimiter + argC + this.delimiter + argD + this.delimiter + argE
}
if (arg6 != 0) {
if (nummer2 % 64 <= 1) {argF=arg6;} else {argF=alle;}
dependentValue = argA + this.delimiter + argB + this.delimiter + argC + this.delimiter + argD + this.delimiter + argE + this.delimiter + argF
}
if (typeof this.options[dependentValue] != "object") { this.options[dependentValue] = new Array(); }
for (var i=1; i<arguments.length; i+=2) {
alert(arguments[i+1]); // -> durchläuft diese Schleife 2 hoch f mal. -> richtige Werte sollten geladen werden.
// Keep track of the longest potential string, to draw the option list
if (arguments[i].length > this.longestString.length) {
this.longestString = arguments[i];
}
this.numberOfOptions++;
this.options[dependentValue][this.options[dependentValue].length] = arguments[i]; // lade den Wert (z.B. Auto)
this.options[dependentValue][this.options[dependentValue].length] = arguments[i+1]; // lade die ID zum Wert (z.B. 1234)
}
}
}
Does anybody have an idea where the mistake in the code can be?
I know, with AJAX it would be much easier to solve, but because of
several reasons I can't use it and have to get back to Javascript.
Great regards,
Norman von Lienen



