Page 1 of 1

Help with showing a form if drop-down value = "Other"

Posted: Sun Nov 13, 2011 1:20 pm
by mikeashfield
Hey, I'm current creating a system in PHP that I want to be able to add orders to the system, and the person processing it will select the customer from a drop down, if the customer does not already exist I would love for there to be an "Other..." option in the drop-down (at the bottom) if the customer isn't in the clients table in the database that will show a hidden form that will allow a client to be added at the same time as order. I would also like a second hidden from to be shown at the same time to allow the person processing the order to add the clients product (for repair) as it will not have a product for the client if the client does not exist. But if they do select a client, then it should search the database table products client_id field for a list of their products and display this in a drop down.

How can I do this? Thanks.

Re: Help with showing a form if drop-down value = "Other"

Posted: Sun Nov 13, 2011 1:54 pm
by danwguy
ok I think I see where you are going and without the code you are currently using I can only speculate, but here's how I see it going...

Code: Select all

/*get list of current customers for the dropdown list*/
$query = "SELECT customer FROM customers";
$run = mysql_query($query);
while($row = mysql_fetch_assoc($run)) {
   $customer[] = $row['customer'];
}
?>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type='text/javascript'>
$(document).ready(function() {
	$("#customer").change(function() {
		var id = $("#customer option:selected").attr('value');
		if(id == '0') {
			$("#hidden").slideDown('slow');
		}
	});
});
</script>
</head>
<body>
<select name='customer' id='customer'>
   <option value='0'>Other</option>
   <?php
           foreach($customer as $key => $name) {
              echo "<option value='".$name."'>".$name."</option>";
           }
     ?>
</select>
<div id='hidden' style='display: none;'>
//INSERT ALL OF YOUR FORM DATA HERE
</div>
</body>
</html>