Page 1 of 1

Dynamic combo box loading problem, Please HeLp

Posted: Tue May 26, 2009 6:39 am
by itbiz2001
Dynamic combo box loading problem, Please HeLp

PHP Guru needed,
Hi All,
I am having issues trying to get a dynamic combo box working.
Requirement : When the user selects a value from the first combo box, I need to include this value as part of a SELECT

WHERE statement to populate the second combo box... See extract of code below:

Code: Select all

 
<select name="add_route" id="add_route" onChange="javascript&#058;loadData()">
<option value="<?php echo $route;?>" SELECTED><?php echo $route;?></option>
<?  $sql=mysql_query("select Id,route_name from routes");
    while($res=mysql_fetch_array($sql))
    {
        $rtId=$res['Id'];
        echo '<option value="'.$rtId.'"';
        echo">".$res['route_name']."</option>";
        
    }
?>
</select>
 
 
 
<select name="add_client"  id="add_client" ">
            <option value="">---</option>
            <?
    $sql=mysql_query("select Id,client_name from client where irouteid=$route");  
    while($res=mysql_fetch_array($sql))
    {
        $clId=$res['Id'];
        echo '<option value="'.$clId.'"';
        echo">".$res['client_name']."</option>";
        
    }
?>
</select>
 
I am a real novice, so any help you can provide is much appreciated :)
Regards
Steve

Re: Dynamic combo box loading problem, Please HeLp

Posted: Tue May 26, 2009 12:23 pm
by mikemike
Hi there,

The way I see it you have two options which are viable:

The first is to reload the page after the first select box has been changed, you'd do this with some very simple JavaScript.
When reloading you'll need to pass the original selectbox value over, your best bet is probably using GET (in the url, accessible via $_GET).

Your second option, and in my opinion the better (but more tricky), is to use AJAX. This will enable you to update the second select box by calling a second PHP script in the background. This is a little more tricky but probably worth the effort in the long run.

Check out these:
http://www.hotscripts.com/forums/php/50 ... elect.html
http://www.daniweb.com/forums/thread122364.html#