By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,334 Members | 2,776 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,334 IT Pros & Developers. It's quick & easy.

Dependant Drop Down Box

P: 4
Ok, I am trying to populate two drop down boxes with the results of a query. I have the first one set up and working but I am stuck on how to pass the results of the first query as a constraint for the second as there is no submit and every example I can find on the web only shows how to pass via post/get into another page. :mad:

Here is what I have for code:


Below are the functions that display the results of the query in a table.
Expand|Select|Wrap|Line Numbers
  1. function dd_joblist($user_name)
  2. {
  3.     $result=mysql_query("SELECT DISTINCT job_name FROM oats_jobs_users_laborCode where user='$user_name' order by job_name;"); 
  4.     if($result)
  5.     {
  6.         echo "<select name=\"job_select\" onchange=\"$job_select=reload(this.form)\"> <option default=\"default\" value=\"*\">Choose One</option>"; 
  7.         while($row=mysql_fetch_row($result))
  8.         { 
  9.             echo "<option value=\"$row[0]\">$row[0]</option>";
  10.         } 
  11.             echo "</select>";
  12.     }
  13.     else
  14.     {
  15.         echo mysql_error($result);
  16.     }
  17. }
  18.  
  19. function dd_laborlist($user_name, $job_select)
  20. {
  21.     $result=mysql_query("SELECT DISTINCT labor_code FROM oats_jobs_users_laborCode where user='$user_name' and job_name='$job_select' order by job_name;"); 
  22.     if($result)
  23.     {
  24.         echo "<select name=\"laborcode\" > <option default=\"default\" value=\"\">Choose One</option>"; 
  25.         while($row=mysql_fetch_row($result))
  26.         { 
  27.             echo "<option value=\"$row[0]\">$row[0]</option>";
  28.         } 
  29.             echo "</select>";
  30.     }
  31.     else
  32.     {
  33.         echo mysql_error($result);
  34.     }
  35. }
  36.  
This is a js that is (hopefully) reloading the page and seems to be storing the first value.
Expand|Select|Wrap|Line Numbers
  1. function reload(form)
  2. {
  3.     var val=form.job_select.options[form.job_select.options.selectedIndex].value;
  4.     self.location='options_screen.inc.php?job_select=' + val ;
  5.     return val;
  6. }
  7.  
This is the HTML code that calls the php functions
Expand|Select|Wrap|Line Numbers
  1. <td><?php dd_joblist($user_name) ?></td>
  2. <td><?php dd_laborlist($user_name, $job_select) ?></td>
  3.  
I am almost to the point of pulling my hair out. Any help would be greatly appreciated
Jul 18 '06 #1
Share this Question
Share on Google+
2 Replies


iam_clint
Expert 100+
P: 1,208
Expand|Select|Wrap|Line Numbers
  1. <select onchange="window.location='select.php?language='+this.value">
  2. <option value="0">- Select Language -</option>
  3. <option value="1" <?if ($language == 1) {?>selected<?}?>>English</option>
  4. <option value="2" <?if ($language == 2) {?>selected<?}?>>Chinese</option>
  5. </select>
  6.  
heres a way to pass the selected value to a page of your desire --- the value can be retrieved by
Expand|Select|Wrap|Line Numbers
  1.  <? $language = $_GET["language"]; ?>
i think this is what you are looking for good luck and let me know if you have any problems with this
Jul 18 '06 #2

P: 4
Expand|Select|Wrap|Line Numbers
  1. onchange="window.location='select.php?language='+this.value"
  2.  
I am assuming this reloads the page back into itself?
Jul 20 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.