function chkthis(str)
{

if(document.form3.itcode.value!='')
{
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("strtxt").innerHTML=xmlhttp.responseText;

  //document.f1.batta.value=document.getElementById("bat1").value;

  var dupvl=document.getElementById("dupitm").value;
  if(dupvl==1)
      {
          alert('ItemCode already exists!');
          document.form3.itcode.focus();
          document.form3.itcode.value='';
            return false;
      }

    }
  }

xmlhttp.open("GET","chkitm.php?itcd="+str,true);
xmlhttp.send();

}

}

<?php
session_start();
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='inde.php'; </script>";
 return;
}
$cname=$_REQUEST['cname'];
$sql="SELECT code,cramt,pin2 FROM khadistaff where brcode='$brcode' and cname='$cname'";
$result = mysqli_query($db,$sql);
$row=mysqli_fetch_row($result);
$led=mysqli_query($db,"select op,drcr from ledger where led ='$cname'")or die(mysqli_error($db));
$r=mysqli_fetch_row($led);
if($r[1]=='Cr')
    {
        $mop_bal=$r[0]*-1;
    }
else
    {
        $mop_bal=$r[0];
    }
$jour=mysqli_query($db,"select sum(dramt),sum(cramt) from journal2 where partic ='$cname'")or die(mysqli_error($db));
$s=mysqli_fetch_row($jour);
$sql="select op,drcr from ledger where led ='$cname'";
//echo $sql;
//echo "<br>";
$sql1="select sum(dramt),sum(cramt) from journal2 where partic ='$cname'";
//echo $sql1;

$mcl_bal=$mop_bal + $s[0] - $s[1];
$inv=mysqli_query($db,"select sum(total) from prod_invoice where customer ='$cname'")or die(mysqli_error($db));
$s=mysqli_fetch_row($inv);
$mbill_amt=$s[0];
$query="select jvno from prod_invoice where customer ='$cname' and brcode='$brcode'";
$rs=mysqli_query($db,$query);
$mdisc_amt=0;
while($row1=mysqli_fetch_array($rs))
{
   $dsgv=mysqli_query($db,"select sum(dramt) from journal2 where partic like 'Stffdiscount%' and jvno='$row1[0]' and brcode='$brcode'");
   $disar=mysqli_fetch_row($dsgv);
   $mdisc_amt=$disar[0];
}
$discbl=$row['2']-$mdisc_amt;
?>
<input name='reg' id='reg' type='text' style='width:160px;border:1px solid grey; border-style:dotted;' value='<? echo $row['0']; ?>' readonly onchange='showinfo(this.value)' onfocus='sel(this.id)' onKeydown='return handleEnter(this, event)'>
<input type='text' name="mclbl" id="mclbl" value="Balance:&nbsp;<? echo $mcl_bal ?>">
<input type='text' name="mblamt" id="mblamt" value="Bill Amount:&nbsp;<? echo $mbill_amt ?>">
<input type='text' name="mcrlmt" id="mcrlmt" value="<? echo $row['1']; ?>">
<input type='text' name="mdslmt" id="mdslmt" value="<? echo $row['2']; ?>">
<input type='text' name="dscntvl" id="dscntvl" value="<? echo $discbl ?>">
<input type='text' name="mdsbl" id="mdsbl" value="<? echo $discbl ?>">
<input type='text' name="mdsbll" id="mdsbll" value="<? echo $mdisc_amt ?>">
<?
session_start();
include("opendb.php");
$tbl2="partmaster";
$partcode=$_GET['key'];
if(isset($_GET['type'])=='name')
{

	$re=mysqli_query($db,"select * from $tbl2 where brcode = '$brcode' and partname like '%$partcode%' limit 10 ") or die("ERR6:".mysqli_error($db));
}
else
{
	$re=mysqli_query($db,"select * from $tbl2 where partcode  like '$partcode%' and brcode = '$brcode' order by partcode asc limit 1 ") or die("ERR6:".mysqli_error($db));
}

$json="";
while($row=mysqli_fetch_array($re))
{
$query="select grp_tax from groupmaster where gname='$row[2]'";
$rs=mysqli_query($db,$query);
$rw=mysqli_fetch_array($rs);
$query1="select lstprice from spareprmast where partcode='$row[0]' and brcode='$brcode'";
$rs1=mysqli_query($db,$query1);
$rw1=mysqli_fetch_array($rs1);
$query2="select curstk from sparestock where itemcode='$row[0]' and brcode='$brcode'";
$rs2=mysqli_query($db,$query2);
$rw2=mysqli_fetch_array($rs2);
$oldprtc=$row[0];
$json.= '{"partcode":"'.$row[0].'","partname":"'.addslashes($row[1]).'","stock":"'.addslashes($rw2[0]).'","rate":"'.addslashes($rw1[0]).'","reduct":"'.addslashes($row[10]).'","tax":"'.addslashes($rw[0]).'"},';
}
if(isset($_GET['type'])=='name')
{

	$re=mysqli_query($db,"select * from $tbl2 where brcode = '$brcode' and partname like '%$partcode%' limit 10 ") or die("ERR6:".mysqli_error($db));
}
else
{
	$re=mysqli_query($db,"select * from $tbl2 where partcode  like '%$partcode%' and partcode!='$oldprtc' and brcode = '$brcode' order by partcode asc limit 9 ") or die("ERR6:".mysqli_error($db));
}

while($row=mysqli_fetch_array($re))
{
$query="select grp_tax from groupmaster where gname='$row[2]'";
$rs=mysqli_query($db,$query);
$rw=mysqli_fetch_array($rs);
$query1="select lstprice from spareprmast where partcode='$row[0]' and brcode='$brcode'";
$rs1=mysqli_query($db,$query1);
$rw1=mysqli_fetch_array($rs1);
$query2="select curstk from sparestock where itemcode='$row[0]' and brcode='$brcode'";
$rs2=mysqli_query($db,$query2);
$rw2=mysqli_fetch_array($rs2);
$json.= '{"partcode":"'.$row[0].'","partname":"'.addslashes($row[1]).'","stock":"'.addslashes($rw2[0]).'","rate":"'.addslashes($rw1[0]).'","reduct":"'.addslashes($row[10]).'","tax":"'.addslashes($rw[0]).'"},';

}
echo '['.trim($json,',').']';
?>


