It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

full dynamic option lists - error

full dynamic option lists - error

Postby novoli on Tue Feb 10, 2009 6:15 am

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
novoli
 
Posts: 4
Joined: Mon Feb 09, 2009 5:32 pm

Re: full dynamic option lists - error

Postby rangana on Tue Feb 10, 2009 11:05 am

Hi Norman,

Good day!

Could you by chance provide us a copy of your markup as well?
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines

Re: full dynamic option lists - error

Postby novoli on Tue Feb 10, 2009 12:40 pm

Hi rangana,

i've added the complete code as attachtment.

Thanks in advance!
You do not have the required permissions to view the files attached to this post.
novoli
 
Posts: 4
Joined: Mon Feb 09, 2009 5:32 pm

Re: full dynamic option lists - error

Postby rangana on Tue Feb 10, 2009 1:46 pm

That code is too much. It's so complicated for a simple tasks like what you desire.

You might find these links a good option too:
http://www.programmersheaven.com/2/FAQ- ... lect-Boxes
http://www.javascriptkit.com/jsref/select.shtml
http://www.webdeveloper.com/forum/showp ... ostcount=2
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines

Re: full dynamic option lists - error

Postby novoli on Tue Feb 10, 2009 2:57 pm

Hi rangana,

thanks for your help, but unfortunately these scripts don't work the way I need it.

The scripts you proposed fill the next option list after you selected an option. I need
to have all possible options in the beginning and want to delete options from the lists
when you select one or more of them.

For example:
-----------
I have two option lists:
in the first one I have as possible options: all - cars - ships
in the second one: all - Ford - Mercedes - container vessel - cruiser ship

If I don't do anything and click the button ' search' I should find all cars and ships in the
following page. If I select 'cars' the second option list should contain 'Ford - Mercedes', if
I select 'cruiser ship' in the second list the first list should contain 'ships'.
-----------

Though I don't use AJAX, I think this should be possible with the existing script, but I cant'
find the main reason why the part I wrote isn't working properly.

Kind regards,
Norman
novoli
 
Posts: 4
Joined: Mon Feb 09, 2009 5:32 pm

Re: full dynamic option lists - error

Postby novoli on Mon Feb 16, 2009 10:30 am

Hello again,

thanks for your help so far! I got to a small problem again, maybe somebody of you can help me.

I am loading my entrys automatically into the dropdown-lists, but there they appear more than once. So I wanted to search the array for the entrys before I load them into it, but my debugger (Firebug) says it's an object. I can't search for entrys in objects, am I right? Does anybody have an idea how to solve this problem?
(attached I sent you a small file with the code).

Thanks in advance!
You do not have the required permissions to view the files attached to this post.
novoli
 
Posts: 4
Joined: Mon Feb 09, 2009 5:32 pm


Who is online

Users browsing this forum: No registered users and 5 guests