Q:

XMLHttpRequest not working

I have an issue in XMLHttpRequest in the code below, it is not working as desired.  Can someone help ! 
In brief: This program is accepting the value from the user on the fly it should update the RATEMASTER_draft table.  If user presses F5 to refresh, it still holds the values, for which I am reading the table again and inserting the values again into the input box. 
But for some reason the data onchange is not updating the table. 
<? php include 'accesscontrol.php'; ? >

<? php
$dbservertype='mysql';
$servername='localhost';
    $dbusername='svga';
$dbpassword='aa!@#';
$dbname='svga3';

connecttodb($servername,$dbname,$dbusername,$dbpassword);
function connecttodb($servername,$dbname,$dbuser,$dbpassword)
{
global $link;
$link=mysql_connect ("$servername","$dbuser","$dbpassword");
if(!$link){die("Could not connect to MySQL");}
mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
}
//////// End of connecting to database ////////
? >

<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head id="Head1" runat="server">
<title>RATEMASTER</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
    $("form:not(.filter) :input:visible:enabled:first").focus();
    });
</script>

<script type="text/javascript">

function showUser(str)
{

if (window. XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft. XMLHTTP");
}
xmlhttp.open("GET","rateaccode.php?q1=" + str,false);
xmlhttp.send();
}

function showprodes(str2)
{
if (window. XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft. XMLHTTP");
}
xmlhttp.open("GET","rateprod.php?q2=" + str2,true);
xmlhttp.send();
}

function showperltr(str3)
{
if (window. XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft. XMLHTTP");
}
xmlhttp.open("GET","rateperltr.php?q3=" + str3,true);
xmlhttp.send();
}

function showperno(str4)
{
if (window. XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft. XMLHTTP");
}
xmlhttp.open("GET","rateperno.php?q4=" + str4,true);
xmlhttp.send();
}

function showpercu(str5)
{
if (window. XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft. XMLHTTP");
}
xmlhttp.open("GET","ratepercu.php?q5=" + str5,true);
xmlhttp.send();
}

function showperkg(str6)
{
if (window. XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else    
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft. XMLHTTP");
}
xmlhttp.open("GET","rateperkg.php?q6=" + str6,true);
xmlhttp.send();
}

function showexcise(str7)
{
if (window. XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft. XMLHTTP");
}
xmlhttp.open("GET","rateexcise.php?q7=" + str7,true);
xmlhttp.send();
}

function showcess(str8)
{
if (window. XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft. XMLHTTP");
  }
xmlhttp.open("GET","ratecess.php?q8=" + str8,true);
xmlhttp.send();
}

function showedu(str9)
{
if (window. XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft. XMLHTTP");
  }
xmlhttp.open("GET","rateedu.php?q9=" + str9,true);
xmlhttp.send();
}

function showfreight(str10)
{
if (window. XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft. XMLHTTP");
  }
xmlhttp.open("GET","ratefreight.php?q10=" + str10,true);
xmlhttp.send();
}

function showcoll(str11)
{
if (window. XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft. XMLHTTP");
  }
xmlhttp.open("GET","ratecoll.php?q11=" + str11,true);
xmlhttp.send();
}

function showloading(str12)
{
if (window. XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft. XMLHTTP");
  }
xmlhttp.open("GET","rateloading.php?q12=" + str12,true);
xmlhttp.send();
}

function showunloading(str13)
{
if (window. XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft. XMLHTTP");
  }
xmlhttp.open("GET","rateunloading.php?q13=" + str13,true);
xmlhttp.send();
}

function showtransport(str14)
{
if (window. XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft. XMLHTTP");
  }
xmlhttp.open("GET","ratetransport.php?q14=" + str14,true);
xmlhttp.send();
}

function showvat(str15)
{
alert ("vat");
if (window. XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft. XMLHTTP");
  }
xmlhttp.open("GET","ratevat.php?q15=" + str15,false);
xmlhttp.send();
}

function showcst(str16)
{
if (window. XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft. XMLHTTP");
  }
xmlhttp.open("GET","ratecst.php?q16=" + str16,true);
xmlhttp.send();
}

function showcstwithout(str17)
{
if (window. XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft. XMLHTTP");
  }
xmlhttp.open("GET","ratecstwithout.php?q17=" + str17,true);
xmlhttp.send();
}

function showtariff(str18)
{
if (window. XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft. XMLHTTP");
  }
xmlhttp.open("GET","ratetariff.php?q18=" + str18,true);
xmlhttp.send();
}

function showbal(str19)
{
if (window. XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft. XMLHTTP");
  }
xmlhttp.open("GET","ratebal.php?q19=" + str19,true);
xmlhttp.send();
}

function showdesc(str20)
{
if (window. XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft. XMLHTTP");
  }
xmlhttp.open("GET","ratedesc.php?q20=" + str20,true);
xmlhttp.send();
}

//----------------------------------------------------

</script>

<style type="text/css">
<!-- 
.sty1 {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 12px;
    font-weight: bold;
}
-->
</style>

</head>

<body onload="document.f1.vat.focus();">
<table width="100%"  border="0" cellpadding="0" cellspacing="0" bgcolor="#026465">
  <tr>
    <td><div align="center"><span class="style1"> Amogh Gases Private Ltd <br></span>
<center class="style5">RATEMASTER - SUPPLEMENTARY INV</center>
<br>

<table width="603" border="0" cellpadding="0" cellspacing="0" class="wrapper">
  <tr>
    <td height="30"><img src="images/bar1.jpg" width="39" height="30" hspace="0" vspace="0" border="0" align="top" /></td>
<td height="30"><a class="MenuBarItemSubmenu" href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image30','','images/bar2mas_top.jpg',1)"><img src="images/bar2mas.jpg" alt="Master" name="Image30" width="71" height="30" hspace="0" vspace="0" border="0" align="top" id="Image30"/></a></td>
<td height="30"><img src="images/bar3.jpg" width="33" height="30" hspace="0" vspace="0" border="0" align="top" /></td>
<td height="30"><a class="MenuBarItemSubmenu" href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image31','','images/bar4sale_top.jpg',1)"><img src="images/bar4sale.jpg" alt="Sales" name="Image31" width="60" height="30" hspace="0" vspace="0" border="0" align="top" id="Image31"/></a></td>
<td height="30">      <a href="#"><img src="images/bar5.jpg" width="34" height="30" hspace="0" vspace="0" border="0" align="top" /></a></td>
<td height="30">     <a class="MenuBarItemSubmenu" href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image32','','images/bar6purch_top.jpg',1)"><img src="images/bar6purch.jpg" alt="Sales" name="Image32" width="101" height="30" hspace="0" vspace="0" border="0" align="top" id="Image32"/></a> </td>
<td height="30">     <img src="images/bar7.jpg" width="33" height="30" hspace="0" vspace="0" border="0" align="top" /></td>
<td height="30">     <img src="images/bar8repo.jpg" width="81" height="30" hspace="0" vspace="0" border="0" align="top" /></td>
<td height="30">     <img src="images/bar9.jpg" width="33" height="30" hspace="0" vspace="0" border="0" align="top" /></td>
<td height="30">     <img src="images/bar10util.jpg" width="80" height="30" hspace="0" vspace="0" border="0" align="top" /></td>
<td height="30">     <img src="images/bar11.jpg" width="38" height="30" hspace="0" vspace="0" border="0" align="top" /></td>
  </td>
  </tr>
</table>
<span class="style7">.</span></div>
</td>
  </tr>
</table>

<? 
    $result = mysql_query("SELECT Ac_code, Ac_desc FROM ACMAST ORDER BY Ac_desc");
    $result2 = mysql_query("SELECT Prod_desc FROM PRODMAST ORDER BY Prod_desc");

//--Table RATEMASTER_draft values------
$res=mysql_query("select * from RATEMASTER_draft WHERE usr='$user'");
$row = mysql_fetch_assoc($res);

$acode=$row['Ac_code'];
$prodesc=$row['Prod_desc'];
$rateno=$row['Rate_perno'];
$rateltr=$row['Rate_perltr'];
$ratecumtr=$row['Rate_percumtr'];
$ratekg=$row['Rate_perkg'];
$exc=$row['Excise_rate'];
$ces=$row['Cess_Excise'];
$edu=$row['Edu_cess'];
$fre=$row['Freight'];
$load=$row['Loading_chrgs'];
$unload=$row['Unloading_chrgs'];    

$cname=mysql_query("select Ac_desc from ACMAST WHERE Ac_code='$acode'");
$cname2=mysql_fetch_assoc($cname);
$cname3=$cname2['Ac_desc'];

echo "<form name='f1'>";
echo "<table width='730' border='0' align='center' cellpadding='0' cellspacing='1'>";
echo "  <tr>";
echo "    <td width='109' height='40'><span class='style3'>Customer </span></td>";

echo "  <td colspan='4'>";
echo "<select name='Accode' onchange=\"showUser(this.value);\"><option value='$acode'>$cname3</option>";
    while($nt=mysql_fetch_assoc($result))
    { //Array or records stored in $nt
    echo "<option value=$nt[Ac_code]>$nt[Ac_desc]</option>";
    }
    echo "</select>";// Closing of list box
echo "</td>";

echo "  <td colspan='3'>";
    echo " <span class='style3'>Gas Type &nbsp;</span> <select name='Proddesc' onchange=\"showprodes(this.value);\"><option value='$prodesc'>$prodesc</option>";
    while($nt2=mysql_fetch_assoc($result2))
    {//Array or records stored in $nt
    echo "<option value='$nt2[Prod_desc]'>$nt2[Prod_desc]</option>";
    /* Option values are added by looping through the array */
    }
    echo "</select>";// Closing of list box

echo "  </td>";
echo "  </tr>";
echo "  <tr>";
echo "    <td><span class='style3'>Rate per no</span></td>";
echo "  <td width='76' height='40'><input name='perno' type='text' size='6' maxlength='6' value='$rateno' onchange=\"showperno(this.value);\"></td>";
echo "  <td width='96'><span class='style3'>Rate per ltr</span></td>";
echo "    <td width='81'><input name='perltr' type='text' size='6' maxlength='6' value='$rateltr' onchange=\"showperltr(this.value);\"></td>";
echo "    <td width='111'><span class='style3'>Rate per cu mtr</span></td>";
echo "    <td width='77'><input name='percu' type='text' size='6' maxlength='6' value='$ratecumtr' onchange=\"showpercu(this.value);\"></td>";
echo "    <td width='117'><span class='style3'>Rate per kg</span></td>";
echo "    <td width='54'><input name='perkg' type='text' size='6' maxlength='6' value='$ratekg' onchange=\"showperkg(this.value);\"></td>";
echo "  </tr>";
echo "  <tr>";
echo "    <td height='40'><span class='style3'>Excise rate</span></td>";
echo "    <td><input name='excise' type='text' size='6' maxlength='6' value='$exc' onchange=\"showexcise(this.value);\"></td>";
echo "    <td><span class='style3'>Cess Excise</span></td>";
echo "    <td><input name='cess' type='text' size='6' maxlength='6' value='$ces' onchange=\"showcess(this.value);\"></td>";
echo "    <td><span class='style3'>Edu cess</span></td>";
echo "    <td><input name='edu' type='text' size='6' maxlength='6' value='$edu' onchange=\"showedu(this.value);\"></td>";
echo "    <td><span class='style3'>Freight</span></td>";
echo "    <td><span class='style3'><input name='freight' type='text' size='6' maxlength='6' value='$fre' onchange=\"showfreight(this.value);\"></span></td>";
echo "  </tr>";
echo "  <tr>";
//echo "    <td height='40'><span class='style3'>Collection chrgs</span></td>";
//echo "    <td><input name='coll' type='text' size='6' maxlength='6' onchange=\"showcoll(this.value);\"></td>";
echo "    <td><span class='style3'>Loading chrgs</span></td>";
echo "    <td><input name='loading' type='text' size='6' maxlength='6' value='$load' onchange=\"showloading(this.value);\"></td>";
echo "    <td><span class='style3'>Unloading chrgs</span></td>";
echo "    <td><input name='unloading' type='text' size='6' maxlength='6' value='$unload' onchange=\"showunloading(this.value);\"></td>";
// echo "    <td><span class='style3'>Transport chrgs</span></td>";
// echo "    <td><input name='transport' type='text' size='6' maxlength='6' onchange=\"showtransport(this.value);\"></td>";
echo "  </tr>";

echo "  <tr>";
echo "    <td><span class='style4'>Suplimentry Invoice</span></td>";

echo "    <td>";
echo "<select name='supli'><option value='1'>Yes</option>";
      echo "</select>";// Closing of list box
echo "</td>";

echo "    <td height='40'><span class='style3'>VAT</span></td>";
echo "    <td><input name='vat' type='text' size='6' maxlength='6' onchange=\"showvat(this.value);\"></td>";
echo "    <td><span class='style3'>CST with CForm</span></td>";
echo "    <td><input name='cst' type='text' size='6' maxlength='6' onchange=\"showcst(this.value);\"></td>";
echo "    <td><span class='style3'>CST without CForm</span></td>";
echo "    <td><input name='cstc' type='text' size='6' maxlength='6' onchange=\"showcstwithout(this.value);\"></td>";
echo "  </tr>";

echo "  <tr>";
echo "    <td height='40'><span class='style4'>Balance Rate</span></td>";
echo "    <td><input name='balrate' type='text' size='6' maxlength='6' onchange=\"showbal(this.value);\"></td>";
echo "    <td><span class='style4'>Description</span></td>";
echo "    <td colspan='5'><input name='desc' type='text' size='70' maxlength='200' value='Transportation and Other Misc Expenses incurred against original Invoice No: ' onchange=\"showdesc(this.value);\"></td>";
echo "  </tr>";

echo "</table>";

echo "</form>";
? >

</body>
</html>

A:

Onchange means; "after change is done" in another way after element has lost focus.  
Only after you finish selecting onchange will be triggered.  
If you want to do that from keyboard just choose item with up and down and select (ENTER) and  then make that element lose focus by pressing TAB
And , for preventing ajax calls to be cached add a unique timestamp data to the urls
You can do it by changing lines like this ;
xmlhttp.open("GET","ratecst.php?q16=" + str16 +"&ts="+new Date().getTime(),true);

