473,472 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to put div id content in the ajax into a input box in html page?

3 New Member
Ajax code
Expand|Select|Wrap|Line Numbers
  1.   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <script type="text/javascript">
  6. function showHint(str)
  7. {
  8.     if (str=="")
  9.       {
  10.       document.getElementById("txtHint").innerHTML="";
  11.       return;
  12.       } 
  13.     if (window.XMLHttpRequest)
  14.       {// code for IE7+, Firefox, Chrome, Opera, Safari
  15.       xmlhttp=new XMLHttpRequest();
  16.       }
  17.     else
  18.       {// code for IE6, IE5
  19.       xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  20.       }
  21.     xmlhttp.onreadystatechange=function()
  22.       {
  23.           if (xmlhttp.readyState==4 && xmlhttp.status==200)
  24.             {
  25.             document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
  26.         }
  27.       }
  28.     xmlhttp.open("GET","ab.php?q="+str,true);
  29.     xmlhttp.send();
  30. }</script>
  31. </head>
  32. <body>
  33. <form action=""> 
  34.   <p>Book No: 
  35.     <input name="book_no" type="text" id="book_no" onKeyUp="showHint(this.value)" />
  36. </p>
  37.   <p>&nbsp;</p>
  38. </form>
  39. <p>
  40.  
  41.   Suggestions: <span id="txtHint"></span></p> 
  42. //i want to display the value into below text box
  43.  Current Number Of copies Available:  <input name="book_no2" type="text" id="book_no2"  />
  44. </body>
  45. </html>
  46.  
  47.  
ab.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $q=$_GET["q"];
  3.  
  4. $con=mysql_connect("localhost","root","")or die("error".mysql_error());
  5. mysql_select_db("library",$con)or die("error".mysql_error());
  6. $sql="SELECT `copies` FROM `book_entry` WHERE `book_no`='".$q."'";
  7. $result = mysql_query($sql);
  8.  
  9. while($row = mysql_fetch_array($result))
  10.   {
  11.   echo $row['copies'];
  12.   }
  13.  
  14. mysql_close($con);
  15.  
  16. ?>
  17.  
nw im doing project in library mangement system.if give book no. in to the text box,thn display the current number of copies availble in other text box.
Mar 24 '11 #1

✓ answered by dgreenhouse

document.getElementById("book_no2").value=xmlhttp. responseText;

4 3041
dgreenhouse
250 Recognized Expert Contributor
Your select statement should be a summation.

i.e.
$sql="SELECT sum(copies) as no_copies FROM book_entry WHERE book_no='".$q."'";
Mar 24 '11 #2
DishaDamz
3 New Member
thanks for ur reply...
but my question is

here the retrieve value from database shown within html form insise div tag .its working well
<div id="txtHint"></div>

txtHint Contain the current number of copies availablle.

now i want to show value of txtHint inside text box
please help me
Mar 24 '11 #3
dgreenhouse
250 Recognized Expert Contributor
document.getElementById("book_no2").value=xmlhttp. responseText;
Mar 24 '11 #4
DishaDamz
3 New Member
Thanku dgreenhouse ..............

ya its work properly in firefox and opera.But doesn't work in IE6.pls help me
Mar 25 '11 #5

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

Similar topics

0
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ...
2
by: John South | last post by:
Hi Can anyone tell me how to insert, within an html page, content that is returned from an asp page on another server? I've seen it done like this: <iframe...
1
by: Heather | last post by:
I found the below content in an HTML page. It is rendering HTML content somehow. I cant understand how, why, from where this is being displayed ? <% nav:displayheader %> Specs: Apache -...
5
by: Dave Vick | last post by:
OK, I've got a requirment to copy some content from an HTML page. It is a failry lengthy page and we want to give the user/reader the ability to click a button and have a section of the page copied...
2
by: justplain.kzn | last post by:
Hi, I have a table with dynamic html that contains drop down select lists and readonly text boxes. Dynamic calculations are done on change of a value in one of the drop down select lists. ...
1
by: MORALBAROMETER | last post by:
Hi all, I want to update MULTIPLE elements of an HTML page using Ajax. for this reason i my response is an xml document. I want to use XSL at the client side to update these elements. How can i...
10
by: paulie | last post by:
Hi, I have been experiencing an issue when trying to use AJAX to reload a DIV area using a timer of 2000ms, which contains a html page with another DIV and javascript. Scenario -------------...
2
by: kenny bones | last post by:
Hello, I'm new here and I'm troubling with something. I'm working on a website which have a treemenu. I've gotten the menu to work alright but I want the DIV which contains the treemenu to have a...
1
by: kkshansid | last post by:
i want this page open only for registered users as much as i know session variable doesnt work in html page kindly help me to do this thanx in advance studentsearch.htm <html> <body> <script...
1
Vkas
by: Vkas | last post by:
my html page is (default.html) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
1
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.