Hi frens..

I have a requirement, where the user selects a option from dropdown, depending on the option selected, the next 2-3 fields must get populated from data coming from db(this must happen without refresh) so i decided to use ajax.

I am getting a error which i am not able to get through.

ajax part

function getVendorInfo()
{
	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");
  	}

	var selectedVendor = document.getElementById("vendor").value;
	//var url = "fetchVendorInfo.php?vendor="; 
       xmlhttp.open("POST", "fetchVendorInfo.php?vendor="+escape(selectedVendor), true); 
	xmlhttp.send();
       
	xmlhttp.onreadystatechange=function()
  	{
	  	if (xmlhttp.readyState==4 && xmlhttp.status==200)
                {
                 document.getElementById("vcontact").innerHTML=xmlhttp.responseText;
    		}
  	} 
}

fetchVendorInfo.php

<?php
 
	$selectedVendor = $_POST['vendor'];//this is the line causing error

	$db = mysql_connect("localhost", "***", "***") or die("Could not connect.");
  	if(!$db)
   	die("no db");
   	mysql_select_db("***",$db);
 
    
	$SqlSelectedVendor = "Select * from company where relation='Vendor' and name='$selectedVendor'";
	$resVendor= mysql_query($SqlSelectedVendor);
	$rowDetail= mysql_fetch_array($resVendor);
	
	$vcontact = $rowDetail['address']."<br />".$rowDetail['city']."<br />".$rowDetail['state']."<br />".$rowDetail['pin']."<br />".$rowDetail['phone'];
  
?>

error i get is
<br />
<b>Notice</b>: Undefined index: vendor in <b>/mnt/opt/lampp/htdocs/***/web/fetchVendorInfo.php</b> on line <b>3</b><br />

pls help me debug this, thanks ppl

i used jquery to get rid of this issue, i could not figure out where i was going wrong in this code, if anyone notices the issue, pls let me know, thanks

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.