|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Linked combo boxes
Heloo! I'm new to javascript so may be you could help out with this problem
I need two combo boxes, the first one is filled from a database and the second is filled according to what you choose in the first one, also from the database. If someone has an example, it would be very helpfull ![]() |
|
#3
|
|||
|
|||
|
Linked combo boxes
In the first combobox there are about 40 options(which are names of groups in a college ex: CIB0405) the second one selects from the database all the students from that group.
|
|
#4
|
|||
|
|||
|
Post an example please.
|
|
#5
|
|||
|
|||
|
Quote:
I have one in php, but the comboboxes are not linked. You basically select the group(there are all the possible groups in the combobox) and the student(there are all the students in that combobox). It takes your choices and goes forward if the selected student(combobox 2) is in the selected group(combobox 1). Here is the sequence of code that selects that creates the comboboxes and fills them with values: [PHPNET]<tr> <th> select the group: </th> <td><?php $link=mysql_connect("localhost","root",""); $db=mysql_select_db("baza_cfbc"); $qry=mysql_query("SELECT id_grupa, grupa From student_grupa"); echo '<select name="grupa">'; while($rez=mysql_fetch_row($qry)) { echo '<option value="'.$rez[1].'">'.$rez[1].'</option>'; } echo '</select>'; ?></td> </tr> <tr> <th>select student: </th> <td><?php $link=mysql_connect("localhost","root",""); $db=mysql_select_db("baza_cfbc"); echo '<select name="student">'; $query = mysql_query("SELECT id_stud, nume, prenume FROM student_persoane, student_stud WHERE student_stud.id_persoana=student_persoane.id_persoana "); while ($rez=mysql_fetch_array($query)) echo '<option value="'.$rez['id_stud'].'">'.$rez['prenume'].' '.$rez['nume'].'</option>'; echo '</select>'; ?></td></tr> <tr>[/PHPNET] |
|
#6
|
|||
|
|||
|
How are the two tables linked?
|
|
#7
|
|||
|
|||
|
Perhaps you can modify the code presented on 2-level combo box
to get what you are looking for. |
|
#8
|
|||
|
|||
|
Quote:
Thanks! thats a good code example, but is there any possibility to work with mysql through javascript? |
|
#9
|
|||
|
|||
|
Quote:
there is a big database out there. Basically the group ID is contained in the table with students. Student ID is contained in the table with persons(that's where the first and last names are). |
|
#10
|
||||||
|
||||||
|
I was bored yesterday, so I actually wrote this out. It is untested, you have been warned. Frontend: Javascript Code:
Backend(getstudents.php): PHP Code:
|