Note that there are some explanatory texts on larger screens.

plurals
  1. POXMLHttpRequest not working
    text
    copied!<p>I have an issue in XMLHttpRequest in the code below, it is not working as desired. Can someone help !</p> <p>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.</p> <p>But for some reason the data onchange is not updating the table.</p> <pre><code>&lt;?php include 'accesscontrol.php'; ?&gt; &lt;?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 //////// ?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html&gt; &lt;head id="Head1" runat="server"&gt; &lt;title&gt;RATEMASTER&lt;/title&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(function () { $("form:not(.filter) :input:visible:enabled:first").focus(); }); &lt;/script&gt; &lt;script type="text/javascript"&gt; 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(); } //---------------------------------------------------- &lt;/script&gt; &lt;style type="text/css"&gt; &lt;!-- .sty1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; } --&gt; &lt;/style&gt; &lt;/head&gt; &lt;body onload="document.f1.vat.focus();"&gt; &lt;table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#026465"&gt; &lt;tr&gt; &lt;td&gt;&lt;div align="center"&gt;&lt;span class="style1"&gt; Amogh Gases Private Ltd &lt;br&gt;&lt;/span&gt; &lt;center class="style5"&gt;RATEMASTER - SUPPLEMENTARY INV&lt;/center&gt; &lt;br&gt; &lt;table width="603" border="0" cellpadding="0" cellspacing="0" class="wrapper"&gt; &lt;tr&gt; &lt;td height="30"&gt;&lt;img src="images/bar1.jpg" width="39" height="30" hspace="0" vspace="0" border="0" align="top" /&gt;&lt;/td&gt; &lt;td height="30"&gt;&lt;a class="MenuBarItemSubmenu" href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image30','','images/bar2mas_top.jpg',1)"&gt;&lt;img src="images/bar2mas.jpg" alt="Master" name="Image30" width="71" height="30" hspace="0" vspace="0" border="0" align="top" id="Image30"/&gt;&lt;/a&gt;&lt;/td&gt; &lt;td height="30"&gt;&lt;img src="images/bar3.jpg" width="33" height="30" hspace="0" vspace="0" border="0" align="top" /&gt;&lt;/td&gt; &lt;td height="30"&gt;&lt;a class="MenuBarItemSubmenu" href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image31','','images/bar4sale_top.jpg',1)"&gt;&lt;img src="images/bar4sale.jpg" alt="Sales" name="Image31" width="60" height="30" hspace="0" vspace="0" border="0" align="top" id="Image31"/&gt;&lt;/a&gt;&lt;/td&gt; &lt;td height="30"&gt; &lt;a href="#"&gt;&lt;img src="images/bar5.jpg" width="34" height="30" hspace="0" vspace="0" border="0" align="top" /&gt;&lt;/a&gt;&lt;/td&gt; &lt;td height="30"&gt; &lt;a class="MenuBarItemSubmenu" href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image32','','images/bar6purch_top.jpg',1)"&gt;&lt;img src="images/bar6purch.jpg" alt="Sales" name="Image32" width="101" height="30" hspace="0" vspace="0" border="0" align="top" id="Image32"/&gt;&lt;/a&gt; &lt;/td&gt; &lt;td height="30"&gt; &lt;img src="images/bar7.jpg" width="33" height="30" hspace="0" vspace="0" border="0" align="top" /&gt;&lt;/td&gt; &lt;td height="30"&gt; &lt;img src="images/bar8repo.jpg" width="81" height="30" hspace="0" vspace="0" border="0" align="top" /&gt;&lt;/td&gt; &lt;td height="30"&gt; &lt;img src="images/bar9.jpg" width="33" height="30" hspace="0" vspace="0" border="0" align="top" /&gt;&lt;/td&gt; &lt;td height="30"&gt; &lt;img src="images/bar10util.jpg" width="80" height="30" hspace="0" vspace="0" border="0" align="top" /&gt;&lt;/td&gt; &lt;td height="30"&gt; &lt;img src="images/bar11.jpg" width="38" height="30" hspace="0" vspace="0" border="0" align="top" /&gt;&lt;/td&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;span class="style7"&gt;.&lt;/span&gt;&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;? $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 "&lt;form name='f1'&gt;"; echo "&lt;table width='730' border='0' align='center' cellpadding='0' cellspacing='1'&gt;"; echo " &lt;tr&gt;"; echo " &lt;td width='109' height='40'&gt;&lt;span class='style3'&gt;Customer &lt;/span&gt;&lt;/td&gt;"; echo " &lt;td colspan='4'&gt;"; echo "&lt;select name='Accode' onchange=\"showUser(this.value);\"&gt;&lt;option value='$acode'&gt;$cname3&lt;/option&gt;"; while($nt=mysql_fetch_assoc($result)) { //Array or records stored in $nt echo "&lt;option value=$nt[Ac_code]&gt;$nt[Ac_desc]&lt;/option&gt;"; } echo "&lt;/select&gt;";// Closing of list box echo "&lt;/td&gt;"; echo " &lt;td colspan='3'&gt;"; echo " &lt;span class='style3'&gt;Gas Type &amp;nbsp;&lt;/span&gt; &lt;select name='Proddesc' onchange=\"showprodes(this.value);\"&gt;&lt;option value='$prodesc'&gt;$prodesc&lt;/option&gt;"; while($nt2=mysql_fetch_assoc($result2)) {//Array or records stored in $nt echo "&lt;option value='$nt2[Prod_desc]'&gt;$nt2[Prod_desc]&lt;/option&gt;"; /* Option values are added by looping through the array */ } echo "&lt;/select&gt;";// Closing of list box echo " &lt;/td&gt;"; echo " &lt;/tr&gt;"; echo " &lt;tr&gt;"; echo " &lt;td&gt;&lt;span class='style3'&gt;Rate per no&lt;/span&gt;&lt;/td&gt;"; echo " &lt;td width='76' height='40'&gt;&lt;input name='perno' type='text' size='6' maxlength='6' value='$rateno' onchange=\"showperno(this.value);\"&gt;&lt;/td&gt;"; echo " &lt;td width='96'&gt;&lt;span class='style3'&gt;Rate per ltr&lt;/span&gt;&lt;/td&gt;"; echo " &lt;td width='81'&gt;&lt;input name='perltr' type='text' size='6' maxlength='6' value='$rateltr' onchange=\"showperltr(this.value);\"&gt;&lt;/td&gt;"; echo " &lt;td width='111'&gt;&lt;span class='style3'&gt;Rate per cu mtr&lt;/span&gt;&lt;/td&gt;"; echo " &lt;td width='77'&gt;&lt;input name='percu' type='text' size='6' maxlength='6' value='$ratecumtr' onchange=\"showpercu(this.value);\"&gt;&lt;/td&gt;"; echo " &lt;td width='117'&gt;&lt;span class='style3'&gt;Rate per kg&lt;/span&gt;&lt;/td&gt;"; echo " &lt;td width='54'&gt;&lt;input name='perkg' type='text' size='6' maxlength='6' value='$ratekg' onchange=\"showperkg(this.value);\"&gt;&lt;/td&gt;"; echo " &lt;/tr&gt;"; echo " &lt;tr&gt;"; echo " &lt;td height='40'&gt;&lt;span class='style3'&gt;Excise rate&lt;/span&gt;&lt;/td&gt;"; echo " &lt;td&gt;&lt;input name='excise' type='text' size='6' maxlength='6' value='$exc' onchange=\"showexcise(this.value);\"&gt;&lt;/td&gt;"; echo " &lt;td&gt;&lt;span class='style3'&gt;Cess Excise&lt;/span&gt;&lt;/td&gt;"; echo " &lt;td&gt;&lt;input name='cess' type='text' size='6' maxlength='6' value='$ces' onchange=\"showcess(this.value);\"&gt;&lt;/td&gt;"; echo " &lt;td&gt;&lt;span class='style3'&gt;Edu cess&lt;/span&gt;&lt;/td&gt;"; echo " &lt;td&gt;&lt;input name='edu' type='text' size='6' maxlength='6' value='$edu' onchange=\"showedu(this.value);\"&gt;&lt;/td&gt;"; echo " &lt;td&gt;&lt;span class='style3'&gt;Freight&lt;/span&gt;&lt;/td&gt;"; echo " &lt;td&gt;&lt;span class='style3'&gt;&lt;input name='freight' type='text' size='6' maxlength='6' value='$fre' onchange=\"showfreight(this.value);\"&gt;&lt;/span&gt;&lt;/td&gt;"; echo " &lt;/tr&gt;"; echo " &lt;tr&gt;"; //echo " &lt;td height='40'&gt;&lt;span class='style3'&gt;Collection chrgs&lt;/span&gt;&lt;/td&gt;"; //echo " &lt;td&gt;&lt;input name='coll' type='text' size='6' maxlength='6' onchange=\"showcoll(this.value);\"&gt;&lt;/td&gt;"; echo " &lt;td&gt;&lt;span class='style3'&gt;Loading chrgs&lt;/span&gt;&lt;/td&gt;"; echo " &lt;td&gt;&lt;input name='loading' type='text' size='6' maxlength='6' value='$load' onchange=\"showloading(this.value);\"&gt;&lt;/td&gt;"; echo " &lt;td&gt;&lt;span class='style3'&gt;Unloading chrgs&lt;/span&gt;&lt;/td&gt;"; echo " &lt;td&gt;&lt;input name='unloading' type='text' size='6' maxlength='6' value='$unload' onchange=\"showunloading(this.value);\"&gt;&lt;/td&gt;"; // echo " &lt;td&gt;&lt;span class='style3'&gt;Transport chrgs&lt;/span&gt;&lt;/td&gt;"; // echo " &lt;td&gt;&lt;input name='transport' type='text' size='6' maxlength='6' onchange=\"showtransport(this.value);\"&gt;&lt;/td&gt;"; echo " &lt;/tr&gt;"; echo " &lt;tr&gt;"; echo " &lt;td&gt;&lt;span class='style4'&gt;Suplimentry Invoice&lt;/span&gt;&lt;/td&gt;"; echo " &lt;td&gt;"; echo "&lt;select name='supli'&gt;&lt;option value='1'&gt;Yes&lt;/option&gt;"; echo "&lt;/select&gt;";// Closing of list box echo "&lt;/td&gt;"; echo " &lt;td height='40'&gt;&lt;span class='style3'&gt;VAT&lt;/span&gt;&lt;/td&gt;"; echo " &lt;td&gt;&lt;input name='vat' type='text' size='6' maxlength='6' onchange=\"showvat(this.value);\"&gt;&lt;/td&gt;"; echo " &lt;td&gt;&lt;span class='style3'&gt;CST with CForm&lt;/span&gt;&lt;/td&gt;"; echo " &lt;td&gt;&lt;input name='cst' type='text' size='6' maxlength='6' onchange=\"showcst(this.value);\"&gt;&lt;/td&gt;"; echo " &lt;td&gt;&lt;span class='style3'&gt;CST without CForm&lt;/span&gt;&lt;/td&gt;"; echo " &lt;td&gt;&lt;input name='cstc' type='text' size='6' maxlength='6' onchange=\"showcstwithout(this.value);\"&gt;&lt;/td&gt;"; echo " &lt;/tr&gt;"; echo " &lt;tr&gt;"; echo " &lt;td height='40'&gt;&lt;span class='style4'&gt;Balance Rate&lt;/span&gt;&lt;/td&gt;"; echo " &lt;td&gt;&lt;input name='balrate' type='text' size='6' maxlength='6' onchange=\"showbal(this.value);\"&gt;&lt;/td&gt;"; echo " &lt;td&gt;&lt;span class='style4'&gt;Description&lt;/span&gt;&lt;/td&gt;"; echo " &lt;td colspan='5'&gt;&lt;input name='desc' type='text' size='70' maxlength='200' value='Transportation and Other Misc Expenses incurred against original Invoice No: ' onchange=\"showdesc(this.value);\"&gt;&lt;/td&gt;"; echo " &lt;/tr&gt;"; echo "&lt;/table&gt;"; echo "&lt;/form&gt;"; ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload