Dependant Drop Down Box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JimS
    New Member
    • Jul 2006
    • 4

    #1

    Dependant Drop Down Box

    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.
    Code:
    function dd_joblist($user_name)
    {
    	$result=mysql_query("SELECT DISTINCT job_name FROM oats_jobs_users_laborCode where user='$user_name' order by job_name;"); 
    	if($result)
    	{
    		echo "<select name=\"job_select\" onchange=\"$job_select=reload(this.form)\"> <option default=\"default\" value=\"*\">Choose One</option>"; 
    		while($row=mysql_fetch_row($result))
    		{ 
    			echo "<option value=\"$row[0]\">$row[0]</option>";
    		} 
    			echo "</select>";
    	}
    	else
    	{
    		echo mysql_error($result);
    	}
    }
    	
    function dd_laborlist($user_name, $job_select)
    {
    	$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;"); 
    	if($result)
    	{
    		echo "<select name=\"laborcode\" > <option default=\"default\" value=\"\">Choose One</option>"; 
    		while($row=mysql_fetch_row($result))
    		{ 
    			echo "<option value=\"$row[0]\">$row[0]</option>";
    		} 
    			echo "</select>";
    	}
    	else
    	{
    		echo mysql_error($result);
    	}
    }
    This is a js that is (hopefully) reloading the page and seems to be storing the first value.
    Code:
    function reload(form)
    {
    	var val=form.job_select.options[form.job_select.options.selectedIndex].value;
    	self.location='options_screen.inc.php?job_select=' + val ;
    	return val;
    }
    This is the HTML code that calls the php functions
    Code:
    <td><?php dd_joblist($user_name) ?></td>
    <td><?php dd_laborlist($user_name, $job_select) ?></td>
    I am almost to the point of pulling my hair out. Any help would be greatly appreciated
  • iam_clint
    Recognized Expert Top Contributor
    • Jul 2006
    • 1207

    #2
    Code:
    <select onchange="window.location='select.php?language='+this.value">
    <option value="0">- Select Language -</option>
    <option value="1" <?if ($language == 1) {?>selected<?}?>>English</option>
    <option value="2" <?if ($language == 2) {?>selected<?}?>>Chinese</option>
    </select>
    heres a way to pass the selected value to a page of your desire --- the value can be retrieved by
    Code:
     <? $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

    Comment

    • JimS
      New Member
      • Jul 2006
      • 4

      #3
      Code:
      onchange="window.location='select.php?language='+this.value"
      I am assuming this reloads the page back into itself?

      Comment

      Working...