PDA

View Full Version : Giving multiple-select new options on the fly


heidar
09-19-2002, 12:56 PM
Iīm using php/mysql to print the code, and also the multi select box have to have names that end with [] for php.

Box1[]
Options printed from database.
Use php also to check which options are selected when page is reloaded.

Box2[]
Php prints possible options from database into Object/2 dimensional array.
When an option is clicked in Box1[] (onchange event) a function evaluates its value(like "001" = text) and find it in the Object/array and adds another element from that Object/array into Box2[] where value = "02*" and output is some string.


First it should look like this:

<select multiple size='4' name='box1[]' onChange='java script:getMultOpts(this)'>
<option value='000' selected>Default
<option value='001'>opt1
<option value='002'>opt2
<option value='003'>opt3
<option value='010'>opt4
<option value='074'>opt5
<option value='087'>opt6
<option value='999'>opt7
</select>
<select size="4" name="box2[]" multiple>
<option value='000' selected>Default
</select>


Than when some values in Box1[] have been selected:
<select multiple size='4' name='box1[]' onChange='java script:getMultOpts(this)'>
<option value='000'>Default
<option value='001' selected>opt1
<option value='002'>opt2
<option value='003' selected>opt3
<option value='010'>opt4
<option value='074'>opt5
<option value='087' selected>opt6
<option value='999'>opt7
</select>
<select size="4" name="box2[]" multiple>
<option value='000' selected>Default
<option value='01*'>opt1
<option value='02*'>opt2
<option value='03*'>opt3
<option value='13*'>opt4
<option value='14*'>opt5
<option value='23*'>opt6
<option value='25*'>opt7
</select>

When opt1 in Box1[] is selected, opt1-opt3 in Box2[] appear.


I need help in coding the object(or multi-dimension array) to hold prepared options for Box2[], and then making them appear in Box2[].

I was thinking of letting PHP output an array wich holds 3 values. The same value as Box1[] holds as index1, values for Box2[] as index2 and the options for Box2[] as the array values like so:
array[index1][index2] = Box2Option.
Is this feasable, or should I use an Object to hold all values ?
If so, how do I create that object ?

I already have the code that shows the values selected from Box1[] in an onChange event.

Also remember the name of the select boxes must end with [] so php can handle them as arrayīs.
And the values in the select-boxes, and array indexes, must look like they are shown, can not be easy integers like 1,2,3... cause they are links to database values.

Havenīt been coding much in javascript, so I donīt even know if this is even possible :rolleyes:

Thx for all help in advance

Ps. English is not my native tounge so if there is anything you dont understand about my questions, pls let my know and Iīll try to re-frase.