473,414 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

ajax script select box is repeated

232 100+
in ajax script
select box is repeated
state 2 times
district 2 times
kindly suggest me to correct this error

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script languphase="javascript" type="text/javascript">
  4. var xmlhttp;
  5.  
  6. function showUser(str)
  7. {
  8. xmlhttp=GetXmlHttpObject();
  9. if (xmlhttp==null)
  10.   {
  11.   alert ("Browser does not support HTTP Request");
  12.   return;
  13.   }
  14. var url="getuser.php";
  15. url=url+"?q="+str;
  16. url=url+"&sid="+Math.random();
  17. xmlhttp.onreadystatechange=stateChanged;
  18. xmlhttp.open("GET",url,true);
  19. xmlhttp.send(null);
  20. }
  21.  
  22. function stateChanged()
  23. {
  24. if (xmlhttp.readyState==4)
  25. {
  26. document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
  27. }
  28. }
  29.  
  30. function GetXmlHttpObject()
  31. {
  32. if (window.XMLHttpRequest)
  33.   {
  34.   // code for IE7+, Firefox, Chrome, Opera, Safari
  35.   return new XMLHttpRequest();
  36.   }
  37. if (window.ActiveXObject)
  38.   {
  39.   // code for IE6, IE5
  40.   return new ActiveXObject("Microsoft.XMLHTTP");
  41.   }
  42. return null;
  43. }
  44. </script>
  45.      <?php require("conn.php");?>
  46. </head>
  47. <body>
  48.  
  49. <?php
  50. //Select a User:
  51.  
  52. $q=$_GET["q"];
  53. if($q=="")
  54. {
  55. $q="assam";
  56. }
  57.  
  58. $sql="SELECT distinct(state) FROM statedistrict";
  59.  
  60. $result = mysql_query($sql);
  61. ?>
  62.  
  63. <select name="users" onchange="showUser(this.value)">
  64. <option value="<?php echo $q; ?>"><?php echo $q; ?></option>
  65. <?php 
  66. while($row = mysql_fetch_array($result))
  67.   {  ?>
  68.  <option value="<?php echo $row[0]; ?>"><?php echo $row[0]; ?></option>
  69.  <?php }
  70.  
  71.  
  72. ?> 
  73. </select>
  74.  
  75.  
  76. <br />
  77. <div id="txtHint"><b>Person info will be listed here.</b></div>
  78. <select name="TR_District" id="TR_District">
  79. <?php
  80.  
  81.  
  82.  
  83. $sql="SELECT district FROM statedistrict WHERE state = '".$q."'";
  84.  
  85. $result = mysql_query($sql);
  86.  
  87.  
  88.  
  89. while($row = mysql_fetch_array($result))
  90.   {
  91.   ?>
  92.  <option value="<?php echo $row[0]; ?>"><?php echo $row[0]; ?></option>
  93.  <?php }
  94.  
  95.  
  96. ?> 
  97. </select>
  98. </form>
  99. </body>
  100. </html> 
Feb 26 '10 #1
3 1998
gits
5,390 Expert Mod 4TB
in your callback function stateChanged() you set the innerHTML of the node txtHint

Expand|Select|Wrap|Line Numbers
  1. document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
... this node doesn't contain anything but text and a <br/> tag which is then replaced ... so all other nodes on the page will stay as they are ...

kind regards
Feb 26 '10 #2
kkshansid
232 100+
thanx for ur valuable suggestion it worked
Feb 26 '10 #3
gits
5,390 Expert Mod 4TB
no problem :) glad to hear that you got it working ....

kind regards
gits
Feb 26 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Frances | last post by:
I literally started learning AJAX just last weekend.. I have this page, http://www.francesdelrio.com/ajax/db2.html, where I'm essentially doing what's here,...
7
by: Ivan Marsh | last post by:
Hey Folks, I'm having a heck of a time wrapping mind around AJAX. Anyone know of a simple, straight-forward example for pulling a simple query from mysql with PHP using AJAX? As I...
1
by: danxavier | last post by:
I successfuly installed dd.php and sajax.php files. It runs fine, but I would like to link the $items to an image. I called the field in mysql with the link "pic". Any help would be AWESOME!!! I've...
1
by: empiresolutions | last post by:
Im using this script, http://www.captain.at/howto-ajax-form-post-get.php, to make an ajax request to php via a drop-down (DD) select. This works fine. Then using this script,...
10
by: trpost | last post by:
I am using ajax / php where I am looking up some info from the database and populating a select list dynamically, however I am running into some sort of size limitation with the ajax.response...
1
by: geevaa | last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3 XMLHttpRequest and AJAX for PHP programmers James Kassemi Introduction: Although the concept isn't entirely new, XMLHttpRequest...
4
by: UKuser | last post by:
Hi, I'm working on the following code, which works fine in Firefox, but not in IE. The problem is its not posting the variable to my page and I'm thinking its something wrong with the...
21
by: Leena P | last post by:
i want to basically take some information for the product and let the user enter the the material required to make this product 1.first page test.php which takes product code and displays...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.