Hi I have this code that will pull the client name and address from the database.
It echo's out the client name for each entry into a dropdown (<option value="<?php echo "$client" ?>"><?php echo "$client" ?></option>
) which is done in a while loop.
Then i have a Javascript that will change the innerHTML of a DIV named 'content' when you select a option in the dropdown - this is unique based on what is pulled from the database. - This is where I can't get it to work.. below is my code any help is much appreciated.
<div id="selectBox">
<div class="ui-widget">
<form>
<label>Select a Client:</label>
<select id="combobox" >
<option value="">Select...</option>
<?php
include "db_conn.php";
callDB();
function callDB(){
$sql = 'SELECT * FROM clientlist';
$query = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_array($query))
{
$ID= $row['id'];
$client= $row["client"];
$postal_add= $row["postal_add"];
?>
<option value="<?php echo "$client" ?>"><?php echo "$client" ?></option>
<?php
}} ?>
</select>
</form>
</div>
</div>
<br>
<div id="content">
</div>
</div>
<script type="text/javascript">
// Script for changing Div
function change()
{
switch (document.getElementById("combobox").value)
{
case "<?php echo $client ?>":
document.getElementById("content").innerHTML = "<h2><?php echo $client ?></h2><b>Postal Address:</b> <?php echo $postal_add ?>"
break;
}
}
</script>
By the time the Javascript is executed (Client), PHP already finished (Server). You will need to build the Javascript from PHP inside the While-Loop and send it to the browser later in the page: