Hi all,
I have 2 SELECT MENUS.
When the FIRST MENU is selected, the PHP code gets data for the SECOND MENU.
Then the user selects from the SECOND MENU to display other data.
This works fine. However, I need the select menus to display their selected values.
At the moment they revert to their default value.
How do I fix this??
Below is my code attempt...
1/ SELECT MENU 1:
<?php
// SELECT CLIENT
$query = "SELECT client_ID, client_name ".
"FROM client";
$result = mssql_query($query) or die('Select Error');
if(isset($client) && ($client !="0"))
{
$option .= '<option value=""selected="selected">'.$client_name.'</option>';
while($row = mssql_fetch_array($result))
{
// SET OPTION
$option .= '<option value="">'.$row['client_name'].'</option>';
} // END WHILE
}
else // if client menu not selected from
{
while($row = mssql_fetch_array($result))
{
// SET OPTION
$option .= '<option value="">'.$row['client_name'].'</option>';
} // END WHILE
}// END IF ELSE
?>
<p>
<label for="client" class="lbl_group">Client</label>
<select name="client" id="client" onchange="change(this.options[selectedIndex].value);">
<option value="0">Select Client</option>
<?php
echo $option;
?>
</select><span class="tip"> 1/ Select Client</span>
</p>
2/ CODE PROCESSING SELECT MENU 1:
$client = $_POST['client'];
// CHECK IF CLIENT SELECTED
if(isset($client) && $client !="0")
{
// GET CLIENT NAME
$query_client = "SELECT client_name ".
"FROM client ".
"WHERE client_ID = $client";
$result_client = mssql_query($query_client) or die('Select Client Error');
$row_client = mssql_fetch_array($result_client);
$client_name = $row_client['client_name'];
// GET FUND NAME
$query_fund = "SELECT fund_ID, client_ID, fund_name ".
"FROM fund_name ".
"WHERE client_ID = $client";
$result_fund = mssql_query($query_fund) or die('Select Fund Name Error');
$options_fund = ''; // SET OPTION VAR
while($row_fund = mssql_fetch_array($result_fund)) // LOOP RESULTS
{
$options_fund .= '<option value="'">'.$row_fund['fund_name'].'</option>';
} // END WHILE
}// END CLIENT CHECK
3/ SELECT MENU 2:
<p>
<label for="name" class="personal">Fund Name</label>
<select name="fund_name" id="fund_name" onchange="change(this.options[selectedIndex].value);">
<option value="0">Select Fund Name</option>
<?php
//echo '<option value="'.$option_list[0].'">'.$option_list[1].'</option>';
echo $options_fund;
?>
</select><span class="tip"> 2/ Select Fund Name</span>
</p>
4/ JAVASCRIPT AFFECTING SELECT MENUS:
<script language="Javascript">
function change()
{
document.getElementById("funds_frm").submit();
}
</script>
thanks!!