title: Ajax State, City Drop Down Menu
body: <p>I'm trying to create a program that when you select a state from the drop down menu, it will display the list of cities for that state in another drop down menu that you can select from. After you choose your city and state, you type in an address, hit submit, and it will display the full address on a new php file. </p>
  
  <p>My issue at the moment is I can get the states displayed, but when the state is selected, it is not giving me the list of options for that city in the second drop down menu. Any help is appreciated, thanks!</p>
  
  <p>You can view the behavior at this <a href="https://web.njit.edu/~csg25/download/select.php" rel="nofollow noreferrer">link</a></p>
  
  <p>select.php</p>
  
  <pre><code>&lt;head&gt;
  &lt;link rel="stylesheet" type="text/css" href="select_style.css"&gt;
  &lt;script type="text/javascript" src="js/jquery.js"&gt;&lt;/script&gt;
  &lt;!DOCTYPE html&gt;
  &lt;form action = "display.php"&gt;
  &lt;script type="text/javascript"&gt;
  
  
  function fetch_select(val)
  {
   $.ajax({
   type: 'post',
   url: 'fetch.php',
   data: {
    get_option:val
   },
   success: function (response) {
    document.getElementById("new_select").innerHTML=response; 
   }
   });
  }
  
  &lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  &lt;p id="heading"&gt;Address Generator&lt;/p&gt;
  &lt;center&gt;
  &lt;div id="select_box"&gt;
   &lt;select onchange="fetch_select(this.value);"&gt;
    &lt;option&gt;Select state&lt;/option&gt;
  
  
    &lt;?php
    include (  "accounts.php"     ) ;
  ( $dbh = mysql_connect ( $hostname, $username, $password ) )
              or die ( "Unable to connect to MySQL database" );
  print "Connected to MySQL&lt;br&gt;";
  mysql_select_db( $project ); 
  
    $select=mysql_query("select state from zipcodes group by state");
    while($row=mysql_fetch_array($select))
    {
     echo "&lt;option&gt;".$row['state']."&lt;/option&gt;";
    }
   ?&gt;
   &lt;/select&gt;
  
   &lt;select id="new_select"&gt;
   &lt;/select&gt;
  
  &lt;div id='2'&gt; &lt;/div&gt;
  &lt;br&gt;&lt;br&gt;
  &lt;input type = text name="address"&gt;Address
  &lt;br&gt;&lt;br&gt;
  &lt;input type = submit&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>fetch.php</p>
  
  <pre><code>&lt;?php
  include(accounts.php);
  if(isset($_POST['get_option']))
  {
   ( $dbh = mysql_connect ( $hostname, $username, $password ) )
              or die ( "Unable to connect to MySQL database" );
  print "Connected to MySQL&lt;br&gt;";
  mysql_select_db( $project );
  
  
   $state = $_POST['get_option'];
   $find=mysql_query("select city from zipcodes where state='$state'");
   while($row=mysql_fetch_array($find))
   {
    echo "&lt;option&gt;".$row['city']."&lt;/option&gt;";
   }
   exit;
  }
  ?&gt;
  </code></pre>