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:
  #1  
Old August 18th, 2004, 01:05 PM
sethadam1 sethadam1 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Orlando, FL
Posts: 223 sethadam1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Dynamic Select Boxes

I'm trying to control the contents of a select box based upon the selection of a first select box. I've done this before, the difference is that now I'm populating the JS arrays with PHP, which is slightly more difficult.

Anyway, this is the output of my PHP, which looks right, but it's not working. Can anyone tell me why this is failing? IE doesn't report an alert error anymore, nor does Mozilla Javascript console.

php Code:
Original - php Code
  1.  
  2. <strong>Group:</strong>
  3.             <select name="groupid" class="formselect" onchange="reload()">
  4.             <option value="1">IT</option>
  5.             <option value="2">Reporting</option>
  6.             <option value="3">Customer Care</option>
  7.             </select>
  8.  
  9. <strong>Assigned To:</strong> </td><td>
  10.             <select name="uid" class="formselect">
  11.             </select>
  12.            
  13. <script type="text/javascript">
  14. var g1 = new Array("Person 1", "Person 2", "Person 3");
  15. var g2 = new Array("Person 4", "Person 5", "Person 6");
  16.  
  17. function loadEm(arr,len){
  18. var options;
  19. for (i=0; i<len; i++){
  20. options += "<option value='"+arr[i]+"'>"+arr[i]+"</option>n";
  21. }
  22. document.forms[myform].uid.innerHTML = options;
  23. return;
  24. }
  25.  
  26. function reload(){
  27. var gi = window.document.forms['modticket'].groupid.selectedIndex;
  28. var gv = window.document.forms['modticket'].groupid.options[gi].value;
  29. if(gv == "IT") loadEm(g1,length(g1));
  30. if(gv == "Reporting") loadEm(g2,length(g2));
  31. if(gv == "Customer Care") loadEm(g3,length(g3));
  32. }
  33.  
  34. </script> 

Reply With Quote
  #2  
Old August 18th, 2004, 02:05 PM
jcaughel jcaughel is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Buffalo, NY, USA
Posts: 283 jcaughel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 4 sec
Reputation Power: 2
Send a message via ICQ to jcaughel Send a message via AIM to jcaughel Send a message via Yahoo to jcaughel
RE: Dynamic Select Boxes

This is not really my forte... It took me a long time to get a similar setup to work, and I did it completely differently... I created a new Option objects to assign to the select.

something like:
Code:
 .
 .
 .
 s=document.myform.uid;
 s.options.length=0;//clear the options
 s.options[s.options.length]=new Option('Person 1','Person 1');//key,value pair
 s.options[s.options.length]=new Option('Person 2','Person 2');//key,value pair
 s.options[s.options.length]=new Option('Person 4','Person 4');//key,value pair
 .
 .
 .



Hope that helps... not sure if it will... good luck!

-Jeff

Reply With Quote
  #3  
Old August 18th, 2004, 02:25 PM
sethadam1 sethadam1 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Orlando, FL
Posts: 223 sethadam1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Dynamic Select Boxes

Jeff,

Could you post the rest of the code so I can try it out?

Thanks a lot!

Reply With Quote
  #4  
Old August 18th, 2004, 03:31 PM
jcaughel jcaughel is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Buffalo, NY, USA
Posts: 283 jcaughel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 4 sec
Reputation Power: 2
Send a message via ICQ to jcaughel Send a message via AIM to jcaughel Send a message via Yahoo to jcaughel
RE: Dynamic Select Boxes

Sure... but I won't get to it till tonight... it is on my home computer buried in some include file...

-Jeff

Reply With Quote
  #5  
Old August 20th, 2004, 01:03 AM
bakertrg's Avatar
bakertrg bakertrg is offline
Contributing User
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Scottsdale AZ, US
Posts: 2,253 bakertrg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m 45 sec
Reputation Power: 4
Send a message via Yahoo to bakertrg
RE: Dynamic Select Boxes

it's really not that hard you can find a million examples of dependent select boxes on the web and then anywhere you need to put a dynamically created variable just replace the current string with

<?php echo $var; ?>

if the length of the list is dynamic then you load the values into an array and step through with a for loop.

one note of caution if you build too many dependent arrays either by having too many levels or too many elements per level this can really really impact loading. It's very easy to get a huge number of elements when you're dynamically building the arrays.

Reply With Quote
  #6  
Old August 20th, 2004, 01:50 AM
jcaughel jcaughel is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Buffalo, NY, USA
Posts: 283 jcaughel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 4 sec
Reputation Power: 2
Send a message via ICQ to jcaughel Send a message via AIM to jcaughel Send a message via Yahoo to jcaughel
RE: Dynamic Select Boxes

I concur with bakertrg on the loading of the page issues. I found my old code but it was unnecessarily complicated. I created a simple example to illustrate what I was trying to say earlier:

http://jeff.caughel.net/js/index.php

The source can be seen at:

http://jeff.caughel.net/js/index.phps


-Jeff

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > Dynamic Select Boxes


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT