|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today! |
|
#1
|
|||
|
|||
|
Dependable combo boxes
I want to create two combo boxes that are dependable on each other if you select from one combo box the other combo box loads with the relevant selections from the database table i think i need to use javascript for this the boxes must read from the database tables though are there any examples i can look at or does any one have a script that they have created i can look at.
|
|
#2
|
|||
|
|||
|
RE: Dependable combo boxes
Since JavaScript is a client side scripting language you can't populate the combo box relative to the selection by going through the database. Inder to do that a request should be sent to the server.
The option for you will be to load all the data on the tables and store it in JavaScript arrays. Then you can simply write the code in JavaScript to populate the combo box according to the selection made. |
|
#3
|
|||
|
|||
|
RE: Dependable combo boxes
That sounds complicated my knowledge on javascript is minimal so i would not know how to do that.
|
|
#4
|
|||
|
|||
|
RE: Dependable combo boxes
Without using JavaScript what can you do is for the onChange() event of the first combo box you submit the selected item value to the samepage. Then you can populate the second combo box with the selected item.
|
|
#5
|
|||
|
|||
|
RE: Dependable combo boxes
Here are my two functions to populate my combo boxes they populate the boxes fine and if i put the second function on a seperate page the box does get populated with the relevant values but i want it on the same page not two seperate pages how do i do that.
Function ExecutableList($Fieldname, $Default) { //This function responds with a select statement. //$Restriction is the division the customers belong to. 0 for all echo(" <select name="$Fieldname">n"); echo(" <option value="-1""); if ($Default == 0) { echo(" selected"); } echo(">Please Select Executable</option>n"); ibase_pconnect($_SESSION['dbpath'], $_SESSION['dbuser'], $_SESSION['dbpass']); $qry = "SELECT EXENO, NAME FROM EXECUTABLES ORDER BY NAME"; $res = ibase_query($qry); while ($resrow = ibase_fetch_row($res)) { echo(" <option value="$resrow[0]""); if ($resrow[0] == $Default) { echo(" selected"); } echo(">$resrow[1]</option>n"); } echo("</select>n"); } Function ModuleList($Fieldname, $Filter, $Default) { //This function responds with a select statement. //$Filter is the executable that was chosen. //$Restriction is the division the customers belong to. 0 for all ibase_pconnect($_SESSION['dbpath'], $_SESSION['dbuser'], $_SESSION['dbpass']); echo(" <select name="$Fieldname">n"); echo(" <option value="-1""); if ($Default == 0) { echo(" selected"); } echo(">Please Select Module</option>n"); $qry = "SELECT L.MODULENO, M.NAME FROM EXECUTABLEMODULES L JOIN MODULES M ON M.MODULENO = L.MODULENO WHERE L.EXENO = $Filter "; $qry = $qry . "ORDER BY NAME"; $res = ibase_query($qry); while ($resrow = ibase_fetch_row($res)) { echo(" <option value="$resrow[0]""); if ($resrow[0] == $Default) { echo(" selected"); } echo(">$resrow[1]</option>n"); } echo("</select>n"); } This is were i call the functions using sessions for the pages but this is not ideal as i want to do it on the same page. ExecutableList("Executable", $_SESSION['NewExecutable']); ModuleList("Module", $_SESSION['NewExecutable'], $_SESSION['NewModule']); |
|
#6
|
|||
|
|||
|
RE: Dependable combo boxes
You can post the values to the same page by using
Code:
<form name="frmmain" action="<?php echo $_SERVER["PHP_SELF"];?>" method="post"> And when you are populating the second combo box, you can use the selected category as the filter parameter. ModuleList($combo2,$_POST["combo1"], $Default) |
|
#7
|
|||
|
|||
|
RE: Dependable combo boxes
Quote:
I am not sure what you mean here? |
|
#8
|
|||
|
|||
|
RE: Dependable combo boxes
Sorry if I was not so clear..
When the user selects a category you post the form values to the same page for the onChange event of the combo box. When populating the second combo box you check whether values are posted to the page. If so you populate it only with the values with the selected category since the selected values is posted to the page.. I hope I'm clear.. |
|
#9
|
|||
|
|||
|
RE: Dependable combo boxes
Are you saying that basically i should use the Post variable instead of using the Session variable?
|
|
#10
|
|||
|
|||
|
RE: Dependable combo boxes
Since values are passed on to the same page you have no need to use session variables.
|
|
#11
|
|||
|
|||
|
RE: Dependable combo boxes
yes i realise that ;) anyway let me give it a try and i will report back still unsure but lets see what i can do if anyone else has anything to chip in feel free.
|
|
#12
|
|||
|
|||
|
RE: Dependable combo boxes
I hope this explains it..
php Code:
|