hi.. just started learning ajax.. could you all please help me with this code..
when i execute i get this

Resource id #3

I have posted the code below.
there are two files..
1) getvendorname.php
2) sales.htm (containing the javascript function)

<script type='text/javascript'>
function getname()
{
  var vendorID = document.getElementById("idvid").value;
  var xmlhttp;
  if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
  }
  else
  {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

  xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById("iddiv").innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.open("GET","getvendorname.php?vendorid="+vendorID,true);
	xmlhttp.send();

}
</script>

<html>
  <head><title>vendor info</title> </head>
  <body>
  <td>Vendor Primary ID:</td>

  <td><input type="text" id="idvid" name="vendor_primary_number" onblur="getname()">
  </td>

  <td>Vendor Primary Name:</td>
  <td> <div id="iddiv"> </div></td>
  </body>
</html>

my php file code:

<?php

	$vid = $_GET['vendorid'];
	
	$connection = mysql_connect('localhost','root','root');
	mysql_select_db('bgm_score', $connection);
	
	
	$r ="select vendor_vendorname from sivendor_info where vendor_vendorid ='$vid'";
	$result = mysql_query($r, $connection);

	
	$row = mysql_fetch_assoc($result);
	echo $row; 
	exit(0);

right now i have just echoed the $result.. i need to put it as the value of the text box.
so i need two things...
1) vendor name to be echoed correctly
2) after i get that correct how can i set it as a value for text box.


database table:
mysql> describe vendor;
+--------------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+-------------+------+-----+---------+-------+
| vendor_vendorid | varchar(8) | YES | | NULL | |
| vendor_vendor_name | varchar(20) | YES | | NULL | |
+--------------------+-------------+------+-----+---------+-------+

please help me..

hey friends... i got the first problem solved...

I am getting the correct value retrieved.

how do i display this as a value of the text box.
I mean how do i change the innerHTML of div tag so that it includes a text box whose value is set to the value retrieved.

$row = mysql_fetch_array($result);
	echo "hello";
	echo $row[0];

You may also try xajax ready to use library. Its good and fast.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.