Note that there are some explanatory texts on larger screens.

plurals
  1. POdynamic select list AJAX and insertion in database table through posting form
    primarykey
    data
    text
    <p>I am wondering to find a solution for my dynamic select list of cities, now I am successfully populated the cities but now unable to post the selected city to database.</p> <p>here is php file:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="show_cities.js"&gt; &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;?php session_start; //library include("conn.php"); ?&gt; &lt;form enctype='multipart/form-data' action='posting_process.php' method='post'&gt;"); &lt;!-- **************************** Country select list ********************** --&gt; Country: &lt;select name="country" onChange="showCities(this.value)"&gt; &lt;?php $sql = 'SELECT country_no, country_name FROM country '.'ORDER BY country_no'; $rs = mysql_query($sql); echo "&lt;option value='0'&gt;"."Select a Country"."&lt;/option&gt;\n "; while($row = mysql_fetch_array($rs)) { echo "&lt;option value=\"".$row['country_no']."\"&gt;".$row['country_name']."&lt;/option&gt;\n "; } ?&gt; &lt;/select&gt; City: &lt;div id="txtCity" class="city_no"&gt; &lt;input type=submit name=action value=Post&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>here is javascript: show_cities.js</p> <pre><code>// JavaScript Document /* &lt;script type="text/javascript"&gt; */ function showCities(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) { document.getElementById("txtCity").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","get_cities.php?q="+str,true); xmlhttp.send(); } /* &lt;/script&gt; */ </code></pre> <p>here is php file: get_cities.php</p> <pre><code>&lt;?php session_start; //library include("conn.php"); $q=$_GET["q"]; $sql="SELECT * FROM city WHERE country_no = ".$q; $result = mysql_query($sql); echo "&lt;select name='city'&gt;"; while($row = mysql_fetch_array($result)) { echo "&lt;option value=\"".$row['city_no']."\"&gt;".$row['city_name'] . "&lt;/option&gt;\n"; } echo "&lt;/select&gt;"; ?&gt; </code></pre> <p>I don't know how to mention the following which return / display the city regards:</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload