Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form action="" method="post" name="booking_form" class="booking" style="width: auto">
- <select name="customer_name" onChange="???????">
- <option value="index.php">Click to select your school </option>
- <?php
- // Make a MySQL Connection
- $username="";
- $password="";
- $database="";
- mysql_connect('localhost',$username,$password);
- @mysql_select_db($database) or die( "Unable to select database");
- $query = "SELECT * FROM table";
- $result = mysql_query($query) or die(mysql_error());
- while($row = mysql_fetch_array($result)){
- $id = $row['id'];
- $school = $row['customer_name'];
- $phone = $row['customer_phone'];
- $address = $row['customer_address'];
- $city = $row['customer_city'];
- $state = $row['customer_state'];
- $zip = $row['customer_zip'];
- $notes = $row['customer_notes'];
- ?>
- <option value="<?php echo $school; ?>"><?php echo "$school".", "."$city"; ?></option>
- <?php }
- ?></select>
- <input type="text" name="customer_address">
- <input type="text" name="customer_city">
- <input type="text" name="customer_state">
- <input type="text" name="customer_zip">
- </form>
- <select name="customer_name">
- <option id='selects' value="index.php">Click to select your school </option>
- $("select[name='customer_name']").change(function(){
- $.post("-YOUR PHP FILE-", customer_name: $(this).val(), function(data){
- schools = data.split(",");
- for(var i in schools){
- $("select[name='customer_name']").append("<option>"+schools[i]+"</option>");
- }
- })
- })
- <?php
- //You connected and got an array contains your school names($schools)
- $schools = implode(",",$schools);
- echo $schools;
- ?>
- var schoolInfo = { id1 : {name:"Name 1", address:"address line" ...},
- id2: {} .... }
- <option value="school" sid="id1">school, city</option>
- .change(function(){
- var sid = $(this).attr('sid');
- $("input[name='customer_address']").val(schoolInfo[sid].address);
- $("input[name='customer_city']").val(schoolInfo[sid].city);
- $("input[name='customer_zip']").val(schoolInfo[sid].zip);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement