Note that there are some explanatory texts on larger screens.

plurals
  1. POGet city id from ajax generating city select box to my original php page
    primarykey
    data
    text
    <p>In my registration form there are many form elements to give users' details for registration in my web site. among those elements there are two select boxes for user to select their district and city. I have created these two select box using ajax. Therefore a user select a district then automatically ajax creating second select box for cities is populating. I used separate PHP page called findcity.php to create city select box. I called this findcity.php page from my original register.php page through onChange attribute. and there I passed the district id with the url to findcity.php page. like wise,</p> <p>Now I need to bring city id to my original register.php page when user select a city from city select box in findcity.php page. my problem is that. I tried to get city Id to register.php page but still I couldn't get it. city id is needed me to send to the database with other form elements' values. </p> <p>can anybody help me to fix my problem? </p> <p>here is my coding for your reference. </p> <p>This code is, from my register.php page </p> <pre><code>&lt;div&gt; &lt;label for="district"&gt;District &lt;img src="../images/required_star.png" alt="required" /&gt; : &lt;/label&gt; &lt;?php require_once ('../includes/config.inc.php'); require_once( MYSQL2 ); $query="select * from district order by district_id"; $result = mysqli_query( $dbc, $query); echo '&lt;select name="district" class="text" onChange="getCity(' . "'" . 'findcity.php?district=' . "'" . '+this.value)"&gt;'; echo '&lt;option value=""&gt;-- Select District --&lt;/option&gt;'; while( $row = mysqli_fetch_array($result, MYSQLI_NUM)) { echo '&lt;option value="' . $row[0] . '"'; // Check for stickyness: if ( isset( $_POST['district']) &amp;&amp; ( $_POST['district'] == $row[0] )) echo ' selected="selected"'; echo " &gt;$row[1]&lt;/option&gt;"; } echo '&lt;/select&gt;'; ?&gt; &lt;/div&gt; &lt;div&gt; &lt;label for="city"&gt;City &lt;img src="../images/required_star.png" alt="required" /&gt; : &lt;/label&gt; &lt;input type="hidden" name="reg_locationid" id="reg_locationid" value="56" /&gt; &lt;div id="citydiv" style="position: relative; top: -14px; left: 130px; margin-bottom: -26px;"&gt; &lt;select name="city" class="text"&gt; &lt;option&gt;-- Select City --&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>this is, from my findcity.php page </p> <pre><code>&lt;?php $districtId=$_GET['district']; require_once ('../includes/configaration.inc.php'); require_once( MYSQLCONNECTION ); $query="select city_id, city_name from city2 where district_id=$districtId"; $result=mysqli_query( $dbc, $query); echo '&lt;select name="city" class="text"&gt; &lt;option&gt;-- Select City --&lt;/option&gt;'; while($row=mysqli_fetch_array($result, MYSQLI_NUM)) { echo '&lt;option value="' . $row[0] . '"'; // Check for stickyness: if ( isset( $_POST['city']) &amp;&amp; ( $_POST['city'] == $row[0] )) { echo ' selected="selected"'; //echo '&lt;input type="hidden" name="city" value="' . $row[0] . '"'; } echo " &gt;$row[1]&lt;/option&gt;"; } echo '&lt;/select&gt;'; ?&gt; </code></pre> <p>These are ajax functions</p> <pre><code>function getXMLHTTP() { //function to return the xml http object 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 getCity(strURL) { 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); } } </code></pre> <p>any comments are greatly appreciated.</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.
    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