title: If no value selected from dropdown, allow textbox to add to mysql table using php, mysql, javascript
body: <p>hi i'm working on triple dropdown for country, state, city using ajax and the reference link is : <a href="http://roshanbh.com.np/2008/01/populate-triple-drop-down-list-change-options-value-from-database-using-ajax-and-php.html" rel="nofollow">http://roshanbh.com.np/2008/01/populate-triple-drop-down-list-change-options-value-from-database-using-ajax-and-php.html</a>. It successfully working but i need if a state has no city in db table then a new text box is appear and the entered values is store in php mysql. what coding i'm implement that. please give some ideas.</p>
  
  <p>code:</p>
  
  <p>Ajax:</p>
  
  <pre><code>&lt;script language="javascript" type="text/javascript"&gt;
    function getXMLHTTP() {
      var xmlhttp = false;
  
      try {
        xmlhttp = new XMLHttpRequest();
      } catch (e) {
        try {
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {
          try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
          } catch (e1) {
            xmlhttp = false;
          }
        }
      }
  
      return xmlhttp;
    }
  
    function getState(countryId) {
      var strURL = "findState.php?country=" + countryId;
      var req = getXMLHTTP();
  
      if (req) {
        req.onreadystatechange = function () {
          if (req.readyState == 4) {
            // only if "OK"
            if (req.status == 200) {
              document.getElementById('statediv').innerHTML = req.responseText;
            } else {
              alert("There was a problem while using XMLHTTP:\n" + req.statusText);
            }
          }
        }
  
        req.open("GET", strURL, true);
        req.send(null);
      }
    }
  
    function getCity(countryId, stateId) {
      var strURL = "findCity.php?country=" + countryId + "&amp;state=" + stateId;
      var req = getXMLHTTP();
  
      if (req) {
        req.onreadystatechange = function () {
          if (req.readyState == 4) {
            // only if "OK"
            if (req.status == 200) {
              document.getElementById('citydiv').innerHTML = req.responseText;
            } else {
              alert("There was a problem while using XMLHTTP:\n" + req.statusText);
            }
          }
        }
  
        req.open("GET", strURL, true);
        req.send(null);
      }
    }
  &lt;/script&gt;
  </code></pre>
  
  <p>Form:</p>
  
  <pre><code>&lt;form method="post" action="" name="form1"&gt;
  &lt;table width="60%" border="0" cellspacing="0" cellpadding="0"&gt;
    &lt;tr&gt;
      &lt;td width="150"&gt;Country&lt;/td&gt;
      &lt;td  width="150"&gt;&lt;select name="country" onChange="getState(this.value)"&gt;
      &lt;option value=""&gt;Select Country&lt;/option&gt;
      &lt;option value="1"&gt;USA&lt;/option&gt;
      &lt;option value="2"&gt;Canada&lt;/option&gt;
          &lt;/select&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr style=""&gt;
      &lt;td&gt;State&lt;/td&gt;
      &lt;td &gt;&lt;div id="statediv"&gt;&lt;select name="state" &gt;
      &lt;option&gt;Select Country First&lt;/option&gt;
          &lt;/select&gt;&lt;/div&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr style=""&gt;
      &lt;td&gt;City&lt;/td&gt;
      &lt;td &gt;&lt;div id="citydiv"&gt;&lt;select name="city"&gt;
      &lt;option&gt;Select State First&lt;/option&gt;
          &lt;/select&gt;&lt;/div&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&amp;nbsp;&lt;/td&gt;
      &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&amp;nbsp;&lt;/td&gt;
      &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>findstate.php</p>
  
  <pre><code>&lt;?php
    include('config.php');
    $country = intval($_GET['country']);
    $query = "SELECT id,statename FROM state WHERE countryid='$country'";
    $result = mysql_query($query);
  ?&gt;
  
  &lt;select name="state" onchange="getCity(&lt;?php echo $country?&gt;,this.value)"&gt;
    &lt;option&gt;Select State&lt;/option&gt;
    &lt;?php while($row=mysql_fetch_array($result)) { ?&gt;
      &lt;option value=&lt;?php echo $row['id']?&gt;&gt;&lt;?php echo $row['statename']?&gt;&lt;/option&gt;
    &lt;?php } ?&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>findcity.php</p>
  
  <pre><code>&lt;?php
    include('config.php');
    $countryId = intval($_GET['country']);
    $stateId = intval($_GET['state']);
    $query = "SELECT id,city FROM city WHERE  stateid='$stateId'";
    $result = mysql_query($query);
  ?&gt;
  
  &lt;select name="city"&gt;
    &lt;option&gt;Select City&lt;/option&gt;
    &lt;?php while($row=mysql_fetch_array($result)) { ?&gt;
      &lt;option value&gt;&lt;?php echo $row['city']?&gt;&lt;/option&gt;
    &lt;?php } ?&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>I want to show if there is no city in any state then a textbox will appear and it's value store to db.</p>