Client Side Things
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesClient Side Things

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old November 3rd, 2003, 08:06 AM
rsa_dude rsa_dude is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: South Africa
Posts: 29 rsa_dude User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to rsa_dude Send a message via AIM to rsa_dude Send a message via Yahoo to rsa_dude
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.

Reply With Quote
  #2  
Old November 3rd, 2003, 08:15 AM
nazly nazly is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Colombo,SriLanka
Posts: 1,325 nazly User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 18 sec
Reputation Power: 3
Send a message via Yahoo to nazly
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.

Reply With Quote
  #3  
Old November 3rd, 2003, 08:19 AM
rsa_dude rsa_dude is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: South Africa
Posts: 29 rsa_dude User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to rsa_dude Send a message via AIM to rsa_dude Send a message via Yahoo to rsa_dude
RE: Dependable combo boxes

That sounds complicated my knowledge on javascript is minimal so i would not know how to do that.

Reply With Quote
  #4  
Old November 3rd, 2003, 08:30 AM
nazly nazly is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Colombo,SriLanka
Posts: 1,325 nazly User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 18 sec
Reputation Power: 3
Send a message via Yahoo to nazly
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.

Reply With Quote
  #5  
Old November 4th, 2003, 05:47 AM
rsa_dude rsa_dude is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: South Africa
Posts: 29 rsa_dude User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to rsa_dude Send a message via AIM to rsa_dude Send a message via Yahoo to rsa_dude
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']);

Reply With Quote
  #6  
Old November 4th, 2003, 06:03 AM
nazly nazly is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Colombo,SriLanka
Posts: 1,325 nazly User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 18 sec
Reputation Power: 3
Send a message via Yahoo to nazly
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)

Reply With Quote
  #7  
Old November 4th, 2003, 06:12 AM
rsa_dude rsa_dude is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: South Africa
Posts: 29 rsa_dude User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to rsa_dude Send a message via AIM to rsa_dude Send a message via Yahoo to rsa_dude
RE: Dependable combo boxes

Quote:
And when you are populating the second combo box, you can use the selected category as the filter parameter.

ModuleList($combo2,$_POST["combo1"], $Default)


I am not sure what you mean here?

Reply With Quote
  #8  
Old November 4th, 2003, 06:20 AM
nazly nazly is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Colombo,SriLanka
Posts: 1,325 nazly User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 18 sec
Reputation Power: 3
Send a message via Yahoo to nazly
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..

Reply With Quote
  #9  
Old November 4th, 2003, 06:27 AM
rsa_dude rsa_dude is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: South Africa
Posts: 29 rsa_dude User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to rsa_dude Send a message via AIM to rsa_dude Send a message via Yahoo to rsa_dude
RE: Dependable combo boxes

Are you saying that basically i should use the Post variable instead of using the Session variable?

Reply With Quote
  #10  
Old November 4th, 2003, 06:32 AM
nazly nazly is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Colombo,SriLanka
Posts: 1,325 nazly User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 18 sec
Reputation Power: 3
Send a message via Yahoo to nazly
RE: Dependable combo boxes

Since values are passed on to the same page you have no need to use session variables.

Reply With Quote
  #11  
Old November 4th, 2003, 06:38 AM
rsa_dude rsa_dude is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: South Africa
Posts: 29 rsa_dude User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to rsa_dude Send a message via AIM to rsa_dude Send a message via Yahoo to rsa_dude
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.

Reply With Quote
  #12  
Old November 4th, 2003, 06:50 AM
nazly nazly is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Colombo,SriLanka
Posts: 1,325 nazly User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 18 sec
Reputation Power: 3
Send a message via Yahoo to nazly
RE: Dependable combo boxes

I hope this explains it..

php Code:
Original - php Code
  1.  
  2. Function ExecutableList($Fieldname, $Default) {
  3. //This function responds with a select statement.
  4. //$Restriction is the division the customers belong to. 0 for all
  5. echo(" <select name="$Fieldname">n");
  6. echo(" <option value="-1"");
  7. if ($Default == 0) {
  8. echo(" selected");
  9. }
  10. echo(">Please Select Executable</option>n");
  11.  
  12. ibase_pconnect($_SESSION['dbpath'], $_SESSION['dbuser'], $_SESSION['dbpass']);
  13. $qry = "SELECT EXENO, NAME FROM EXECUTABLES ORDER BY NAME";
  14. $res = ibase_query($qry);
  15. while ($resrow = ibase_fetch_row($res)) {
  16. echo(" <option value="$resrow[0]"");
  17. if ($resrow[0] == $Default) {
  18. echo(" selected");
  19. }
  20. echo(">$resrow[1]</option>n");
  21. }
  22. echo("</select>n");
  23. }
  24.  
  25. Function ModuleList($Fieldname, $Filter, $Default) {
  26. //This function responds with a select statement.
  27. //$Filter is the executable that was chosen.
  28. //$Restriction is the division the customers belong to. 0 for all
  29. ibase_pconnect($_SESSION['dbpath'], $_SESSION['dbuser'], $_SESSION['dbpass']);
  30. echo(" <select name="$Fieldname">n");
  31. echo(" <option value="-1"");
  32. if ($Default == 0) {
  33. echo(" selected");
  34. }
  35. echo(">Please Select Module</option>n");
  36. $qry = "SELECT L.MODULENO, M.NAME FROM EXECUTABLEMODULES L JOIN MODULES M ON M.MODULENO = L.MODULENO WHERE L.EXENO = $Filter ";
  37. $qry = $qry . "ORDER BY NAME";
  38. $res = ibase_query($qry);
  39.  
  40. while ($resrow = ibase_fetch_row($res)) {
  41. echo(" <option value="$resrow[0]"");
  42. if ($resrow[0] == $Default) {
  43. echo(" selected");
  44. }
  45. echo(">$resrow[1]</option>n");
  46. }
  47.  
  48. echo("</select>n");
  49. }
  50. 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.
  51. echo "<form name="frmmain" action="$_SERVER["PHP_SELF"]" method="post">";
  52.  
  53. ExecutableList("Executable", $_SESSION['NewExecutable']);
  54. if(isset($_POST["Executable"])){
  55.     ModuleList("Module", $_POST["Executable"], $_SESSION['NewModule']);
  56. }