Reply
Dynamic linked list boxes???
Old 07-15-2004, 12:33 AM Dynamic linked list boxes???
Novice Talker

Posts: 8
Hey everyone, I'm kinda new to this so excuse me if this is an unclear question.

I have two list boxes: Departments and Employees. When the user first goes to the page, I want them to have Departments(populated from my database), but no Employees yet. Once the user clicks on a Department, I want the Employees listbox to be populated with Employees from that Department.

I've heard that I can do an onclick or onchange event for this using a POST variable, but whenever I try it, it won't work properly. Can anyone help with this, or have any examples? Any help is appreciated.
Quest is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 07-15-2004, 08:59 AM
Ultra Talker

Posts: 377
you can't do in only with JS - first of all you have to store your info in db or in a simple file (to set a accordance betweent department and employees). and second - you have to use a script that will "onclick" get the department name and then get all employees and form a dynamic listbox...
__________________
andrews_john
www.softwareforhosting.com
andrews_john is offline
Reply With Quote
View Public Profile Visit andrews_john's homepage!
 
Old 07-15-2004, 09:22 AM
Republikin's Avatar
Super Moderator

Posts: 3,191
I would do this with php and mysql looping through the results on each pass adding an option to the list box.
Republikin is offline
Reply With Quote
View Public Profile
 
Old 07-15-2004, 09:28 AM
scottfree's Avatar
Extreme Talker

Posts: 234
Location: Hamburg
Had to do this a while back and solved it with perl and HTML, but you need to learn a little Perl and I am sure you are not too keen on that. As far as I know this is not possible with pure HTML.
__________________
I think, therefore I am..... I think.
scottfree is offline
Reply With Quote
View Public Profile Visit scottfree's homepage!
 
Old 07-15-2004, 09:52 AM
Republikin's Avatar
Super Moderator

Posts: 3,191
Let me get more specific on my method...

PHP Code:
// Lets assume that the info has already been queried from the db in
// the variable $employees
<?php

echo '<select name="employees">';
while(
$res $employees) {
  echo 
'<option value="'.$res['id'].'">'.$res['name'].''
}
echo 
'</select>';

?>
Thats a very rough idea of how to do it. There are several methods but this will work.

Last edited by Republikin : 07-15-2004 at 09:54 AM.
Republikin is offline
Reply With Quote
View Public Profile
 
Old 07-15-2004, 09:59 AM
Novice Talker

Posts: 8
Thanks for all the replys.

In my Employees database, I have the fields 'Name', 'Department', etc. So what I want to do is when the user selects a department, the employee listbox is populated with employee 'Name's that have that department in their rows. I guess what I'm not getting is how to do an "onclick" or "onchange" with the department listbox that will save the user's choice in order for me to reference it when I populate the employee listbox. And do I have to refresh the page for this?

Once again thanks for all the help
Quest is offline
Reply With Quote
View Public Profile
 
Old 07-15-2004, 10:41 AM
Novice Talker

Posts: 8
Do I have to do this with JavaScript, to save the department choice in order to reference it? If so what do I do for the "onclick" event, and how should the employee list reference it?
Quest is offline
Reply With Quote
View Public Profile
 
Old 07-15-2004, 10:54 AM
scottfree's Avatar
Extreme Talker

Posts: 234
Location: Hamburg
Try using the "onselect=doSomething". This works with all input and textarea elements
__________________
I think, therefore I am..... I think.
scottfree is offline
Reply With Quote
View Public Profile Visit scottfree's homepage!
 
Old 07-15-2004, 11:44 AM
Novice Talker

Posts: 8
Yes, the onselect will work fine. But, what should I put as the function or whatever that it's gonna call. For example I've been trying to write a function that get called "onselect" and stores the department value, and then re-populates the employee listbox. The only problem is it's not working, haha.
Quest is offline
Reply With Quote
View Public Profile
 
Old 07-15-2004, 11:54 AM
scottfree's Avatar
Extreme Talker

Posts: 234
Location: Hamburg
I really donīt think this is possible with pure HTML, what are you using?
I did this with perl.
The file prints out a HTML page with the first select box populated from the database, which is done by perl and stored in a hash. I also have a hidden param on the page, which is set to whatever, when the form is submitted. When it is submitted, the same file is called again but now the hidden param value has changed and it goes into an if loop {if (param('cmd') == 'whatever') print the next page} it now has the value from the first select box stored and perl uses this to pull the data out of the database, stores it in a hash and populates the second selectbox.
I hope this helps, if you need a little code, I can try to put something together tomorrow, I have to go home now and relax.
Cheers.
__________________
I think, therefore I am..... I think.
scottfree is offline
Reply With Quote
View Public Profile Visit scottfree's homepage!
 
Old 07-15-2004, 12:03 PM
Novice Talker

Posts: 8
I'm using PHP. Sorry, I should have said that from the beginning. I appreciate the help though.
Quest is offline
Reply With Quote
View Public Profile
 
Old 07-15-2004, 03:30 PM
Novice Talker

Posts: 8
Nevermind I got it, thanks for the help!
Quest is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Dynamic linked list boxes???
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.15470 seconds with 12 queries