javascript - can not retrieve data in to text box -
in form have 3 listbox elements working fine, need update when select state similar states city added state select list. can this?
my dropdown3.php file is:
<html> <body> <?php session_start(); require "head.php"; require "config.php"; echo "</head><body>"; echo "<table><tr><form method=post id=f1 action=dropdown3-ck.php> <td>"; $sql="select * plus2_country"; echo "<select class='form-control' id=country_code name=country_code><option value=''>select country</option>"; foreach ($dbo->query($sql) $row) { echo "<option value=$row[country_code] >$row[country]</option>"; } echo "</select></td> <td><select class='form-control' id=state_id name=state_id><option value=''>select state</option></select> </td>"; echo "<td><select class='form-control' id=city_id name=city_id><option value=''>select city</option></select>"; //<input name="city_id" type="text" id="city_id" value='' >"; //i use in tex box echo "</td><td><input type=submit value=submit id=b1></div></form></td></tr></table>"; ?> <script> $(document).ready(function() { ////////////////country list box on change//////////////////// $("#country_code").change(function(){ // change function of listbox $("#state_id,#city_id").empty();// remove existing options $.post( "dropdown3ck.php", {"country_code":$('#country_code').val()},function(return_data,status){ $("#state_id").append("<option value=''>select state</option>"); $.each(return_data.state, function(key,value){ $("#state_id").append("<option value=" + value.state_id +">"+value.state_id + ':' + value.state+"</option>"); }); },"json"); }); /////////////////////////// ////////////// state list box on change ////////////////////// $("#state_id").change(function(){ // change function of listbox $.post( "dropdown3ck.php", {"state_id":$('#state_id').val()},function(return_data,status){ $.each(return_data.city, function(key,value){ $("#city_id").append("<option value=" + value.city_id +">"+value.city+"</option>"); }); },"json"); }); }) </script> </body> </html>
my dropdown3ck.php file is:
<?php require "config.php"; // connection details error_reporting(0);// no error reporting there $country_code=$_post['country_code'];// $state_id=$_post['state_id']; /// state id if(strlen($country_code) > 0){ $q_country="select state,state_id plus2_state country_code = :country_code"; } $sth = $dbo->prepare($q_country); $sth->bindparam(':country_code',$country_code,pdo::param_str, 15); $sth->execute(); $state = $sth->fetchall(pdo::fetch_assoc); $q_state="select city_id,city plus2_city "; if(strlen($state_id) > 0){ $q_state= $q_state . " state_id = :state_id "; } $sth = $dbo->prepare($q_state); $sth->bindparam(':state_id',$state_id,pdo::param_str, 25); $sth->execute(); $city = $sth->fetchall(pdo::fetch_assoc); $main = array('state'=>$state,'city'=>$city,'value'=>array("state1"=>"$state1","city1"=>"$city1")); echo json_encode($main); ?>
Comments
Post a Comment