Ik heb een Jscriptje om een 'dropdown' te laten communiceren met een tweede 'dropdown'. Dit werkt, zoals je kunt zien, via arrays in Jscript. Nu wil ik deze arrays vullen met php. Tot zover werkt dit nog. Sinds ik de arrays vul met PHP (database) gaat het legen van de arrays gaat niet MEER goed. Kies je in de eerste dropdown voor de tweede optie 'tasks' krijg je naast de attributen van tasks ook de attributen van de eerste optie 'persons' in de tweede 'dropdown'. Kies je voor de derde optie 'projects' krijg je (dus) alle variabelen. Waarom wordt de tweede dropdown niet meer proper geleegd?
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
| <HTML> <HEAD> <TITLE> drop down </TITLE> <?php $handle = ora_plogon("...@...", "...")or die("Error while connecting Oracle Database"); $cursor = ora_open($handle); ora_commitoff($handle); function fill_js_array($cursor,$query) { // Run query: $query global $returnstring; // string that will be returned @ora_parse($cursor, $query); @ora_exec($cursor); $numcols = ora_numcols($cursor); for($column=0; $column < $numcols; $column++){ $returnstring = $returnstring . "'"; $returnstring = $returnstring . ora_columnname($cursor,$column); $returnstring = $returnstring . "',"; } Return $returnstring; } echo(" <script language='javascript'> var lists = new Array(); // First set of text and values lists['persons'] = new Array(); lists['persons'][0] = new Array( ".fill_js_array($cursor,"select * from persons")." ''); lists['persons'][1] = new Array( ".fill_js_array($cursor,"select * from persons")." ''); // Second set of text and values lists['tasks'] = new Array(); lists['tasks'][0] = new Array( ".fill_js_array($cursor,"select * from tasks")." ''); lists['tasks'][1] = new Array( ".fill_js_array($cursor,"select * from tasks")." ''); // Third set of text and values lists['projects'] = new Array(); lists['projects'][0] = new Array( ".fill_js_array($cursor,"select * from projects")." ''); lists['projects'][1] = new Array( ".fill_js_array($cursor,"select * from projects")." ''); </script> <script language='javascript'> // This function goes through the options for the given // drop down box and removes them in preparation for // a new set of values function emptyList( box ) { // Set each option to null thus removing it while ( box.options.length ) box.options[0] = null; } // This function assigns new drop down options to the given // drop down box from the list of lists specified function fillList( box, arr ) { // arr[0] holds the display text // arr[1] are the values for ( i = 0; i < arr[0].length; i++ ) { // Create a new drop down option with the // display text and value from arr option = new Option( arr[0][i], arr[1][i] ); // Add to the end of the existing options box.options[box.length] = option; } // Preselect option 0 box.selectedIndex=0; } // This function performs a drop down list option change by first // emptying the existing option list and then assigning a new set function changeList( box ) { // Isolate the appropriate list by using the value // of the currently selected option list = lists[box.options[box.selectedIndex].value]; // Next empty the slave list emptyList( box.form.slave ); // Then assign the new list values fillList( box.form.slave, list ); } </script>"); ?> </HEAD> <body onload="changeList(document.forms['drops'].master)"> <form name="drops" method="get" action="#"> <table border=0 bgcolor="#ffeecc"> <tr> <td>1</td> <td><select name="master" size=1 onchange="changeList(this)"> <option value="persons">persons</option> <option value="tasks">tasks</option> <option value="projects">projects</option> </select> </td> </tr> <tr> <td>2</td> <td> <select name="slave" size=1> <option>it</option> </select> </td> </tr> </table> </form> </BODY> </HTML> |