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.
here is php file:
Code:<html> <head> <script type="text/javascript" src="show_cities.js"> </script> </head> <body> <?php session_start; include("conn.php"); ?> <form enctype='multipart/form-data' action='posting_process.php' method='post'>"); <!-- **************************** Country select list ********************** --> Country: <select name="country" onChange="showCities(this.value)"> <?php $sql = 'SELECT country_no, country_name FROM country '.'ORDER BY country_no'; $rs = mysql_query($sql); echo "<option value='0'>"."Select a Country"."</option>\n "; while($row = mysql_fetch_array($rs)) { echo "<option value=\"".$row['country_no']."\">".$row['country_name']."</option>\n "; } ?> </select> City: <div id="txtCity" class="city_no"> </div> <input type=submit name=action value=Post> </form> </body> </html>
here is javascript: show_cities.js
Code:// JavaScript Document /* <script type="text/javascript"> */ function showCities(str) { if (str=="") { document.getElementById("txtCity").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 && xmlhttp.status==200) { document.getElementById("txtCity").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","get_cities.php?q="+str,true); xmlhttp.send(); } /* </script> */
here is php file: get_cities.php
don't know how to mention the txtcity in my insert statement to insert in database, all the other columns are ok, but city is blank.Code:<?php session_start; //library include("conn.php"); $q=$_GET["q"]; $sql="SELECT * FROM city WHERE country_no = ".$q; $result = mysql_query($sql); echo "<select name='city'>"; while($row = mysql_fetch_array($result)) { echo "<option value=\"".$row['city_no']."\">".$row['city_name'] . "</option>\n"; } echo "</select>"; ?>
regards:


Reply With Quote

Bookmarks