Advertisement
Guest User

Untitled

a guest
Feb 26th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. <form action="" method="post" name="booking_form" class="booking" style="width: auto">
  2. <select name="customer_name" onChange="???????">
  3. <option value="index.php">Click to select your school </option>
  4. <?php
  5.  
  6. // Make a MySQL Connection
  7.  
  8. $username="";
  9.  
  10. $password="";
  11.  
  12. $database="";
  13.  
  14. mysql_connect('localhost',$username,$password);
  15.  
  16. @mysql_select_db($database) or die( "Unable to select database");
  17.  
  18. $query = "SELECT * FROM table";
  19. $result = mysql_query($query) or die(mysql_error());
  20. while($row = mysql_fetch_array($result)){
  21.  
  22. $id = $row['id'];
  23. $school = $row['customer_name'];
  24. $phone = $row['customer_phone'];
  25. $address = $row['customer_address'];
  26. $city = $row['customer_city'];
  27. $state = $row['customer_state'];
  28. $zip = $row['customer_zip'];
  29. $notes = $row['customer_notes'];
  30. ?>
  31. <option value="<?php echo $school; ?>"><?php echo "$school".", "."$city"; ?></option>
  32. <?php }
  33.  
  34. ?></select>
  35. <input type="text" name="customer_address">
  36. <input type="text" name="customer_city">
  37. <input type="text" name="customer_state">
  38. <input type="text" name="customer_zip">
  39. </form>
  40.  
  41. <select name="customer_name">
  42. <option id='selects' value="index.php">Click to select your school </option>
  43.  
  44. $("select[name='customer_name']").change(function(){
  45. $.post("-YOUR PHP FILE-", customer_name: $(this).val(), function(data){
  46. schools = data.split(",");
  47. for(var i in schools){
  48. $("select[name='customer_name']").append("<option>"+schools[i]+"</option>");
  49. }
  50. })
  51. })
  52.  
  53. <?php
  54. //You connected and got an array contains your school names($schools)
  55. $schools = implode(",",$schools);
  56. echo $schools;
  57. ?>
  58.  
  59. var schoolInfo = { id1 : {name:"Name 1", address:"address line" ...},
  60. id2: {} .... }
  61.  
  62. <option value="school" sid="id1">school, city</option>
  63.  
  64. .change(function(){
  65. var sid = $(this).attr('sid');
  66. $("input[name='customer_address']").val(schoolInfo[sid].address);
  67. $("input[name='customer_city']").val(schoolInfo[sid].city);
  68. $("input[name='customer_zip']").val(schoolInfo[sid].zip);
  69. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement