Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. city dropdown
  2.  
  3. <div class="form-group">
  4. <label for="">City</label>
  5. <select name="ct" id="ct" onChange="getPin()" class="form-control">
  6. <option value="0">Select City</option>
  7. </select>
  8. <span id="error11" class="alert-danger"></span>
  9. </div>
  10.  
  11. When I am trying to fetch Pincode according to the selected city, It's
  12. not working. Below is the file where I need to bring value. Do I need to
  13. write value inside input text box to show the Pincode.
  14.  
  15. Pincode Inputbox
  16.  
  17. <div class="form-group">
  18. <label for="">Pin</label>
  19. <input type="text" class="form-control" name="pn" id="pin"
  20. autocomplete="off">
  21. <span id="error12" class="alert-danger"></span>
  22. </div>
  23.  
  24. Ajax fetch Pincode
  25.  
  26. function getPin()
  27. {
  28. var ct=document.getElementById('ct').value;
  29. var p;
  30. if(window.XMLHttpRequest)
  31. {
  32. p=new XMLHttpRequest();
  33. }
  34. else
  35. {
  36. p=new ActiveXObject("Microsoft.XMLHTTP");
  37. }
  38. p.open("POST","pin.php?ct_id="+ct,true);
  39. p.send();
  40. p.onreadystatechange=function()
  41. {
  42. if(p.readyState==4)
  43. {
  44. document.getElementById('pin').value=p.responseText;
  45. }
  46. }
  47. }
  48.  
  49. pin.php page
  50.  
  51. <?php
  52. include('connection.php');
  53. if(isset($_POST['ct_id']))
  54. {
  55. $ctid=$_POST['ct_id'];
  56. $pin_db="select * from pincode where cityId='$ctid'";
  57. $pin_db_exe=$con->query($pin_db) or mysqli_error();
  58. $ftch_pin=$pin_db_exe->fetch_array();
  59. print_r($ftch_pin);
  60. }
  61. ?>
  62.  
  63. When I am selecting the city, in Pincode input text its showing error.
  64. Please need some help.
  65. <p><br>Success</p><br>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement