needs_upgrade Posted June 22, 2011 Share Posted June 22, 2011 I'm having problems with my scripts. Javascipt output is inconsistent. What i mean is that if i'm accessing the system on my machine, the system outputs the correct figures. But when it is accessed using another machine, incorrect figures are displayed. We are all using google chrome so i guess the browser is not the issue. Javascript is enabled. The operating system might be the issue but im not sure. The system is launched at brinkster.com here are the codes: <form name="AddOrder" action="add_order.php" method="POST"> <tbody class="data"> <?PHP for ($i=1; $i<11; $i++) { $m = fmod($i, 2); if ($m == 0) { ?><tr class="even"><?PHP } else { ?><tr class="odd"><?PHP } ?> <td align="center"><?PHP echo $i ?></td><td align="left"><select id="product_id<?PHP echo $i ?>" name="product_id<?PHP echo $i ?>" onchange="OrderRequest('sell_price<?PHP echo $i ?>', 'get_price.php?product_id=', 'promo<?PHP echo $i ?>', 'get_promo.php?product_id=', 'qty_mul<?PHP echo $i ?>', 'get_qty_mul.php?product_id=', 'price_mul<?PHP echo $i ?>', 'get_price_mul.php?product_id=', 'product_id<?PHP echo $i ?>')"><option value="0">Product Name</option> <?PHP $sql = "SELECT product_id, product_name FROM products WHERE ptype = 1 ORDER BY product_name"; $pres = mysql_query($sql); while ($prow = mysql_fetch_array($pres)) { print "<option value=$prow[0]>$prow[1]</option>"; } mysql_free_result($pres); ?></select></td> <td align="center"><input type="text" size="10" id="promo<?PHP echo $i ?>" name="promo<?PHP echo $i ?>" readonly="true"></td> <td align="center"><input type="text" size="7" id="price_mul<?PHP echo $i ?>" name="price_mul<?PHP echo $i ?>" style="text-align:right;"></td> <td align="center"><input type="text" size="7" id="qty_mul<?PHP echo $i ?>" name="qty_mul<?PHP echo $i ?>" style="text-align:right;"></td> <td align="center"><input type="text" size="7" id="sell_price<?PHP echo $i ?>" name="sell_price<?PHP echo $i ?>" readonly="true" style="text-align:right;"></td> <td align="center"><input type="text" size="7" id="quantity<?PHP echo $i ?>" name="quantity<?PHP echo $i ?>" onblur="PromoRequest('sell_price<?PHP echo $i ?>', 'get_promo_price.php', 'net_price<?PHP echo $i ?>', 'get_net_price.php', 'tquantity<?PHP echo $i ?>', 'product_id<?PHP echo $i ?>', 'quantity<?PHP echo $i ?>', 'sell_price<?PHP echo $i ?>', 'price_mul<?PHP echo $i ?>', 'qty_mul<?PHP echo $i ?>')" style="text-align:right;"></td> <td align="center"><input type="text" size="7" id="tquantity<?PHP echo $i ?>" name="tquantity<?PHP echo $i ?>" readonly="true" style="text-align:right;" onblur="getOrderTPrice()"></td> <td align="center"><input type="text" size="7" id="net_price<?PHP echo $i ?>" name="net_price<?PHP echo $i ?>" readonly="true" style="text-align:right;" onblur="getOrderTPrice()"></td> </tr> <?PHP } ?> <tr class="odd"> <td colspan="7" align="right"><b>Line Totals</b></td> <td align="center"><input type="text" size="7" id="tqty" name="tqty" readonly="true" style="text-align:right;"></td> <td align="center"><input type="text" size="7" id="tnet_price" name="tnet_price" readonly="true" style="text-align:right;"></td> </tr> <tr class="odd"><td align="center" colspan="9"> <input type="hidden" name="submitted" value="1"> <input type="hidden" name="token" value="<?PHP echo $token ?>"> <input type="hidden" name="order_id" value="<?PHP echo $order_id ?>"> <input type="reset"> <input onClick="valAddOrder()" type="button" value="Submit"></td></tr> </tbody> </form> javascript: function PromoRequest(target_div1, file1, target_div2, file2, target_div3, product_id, quantity, sell_price, price_mul, qty_mul) { var MyHttpRequest = false; var MyHttpRequest2 = false; var MyHttpLoading = 'Loading...'; var ErrorMSG = 'Sorry - No XMLHTTP support in your browser, buy a newspaper instead'; var customer_id = document.AddOrder.customer_id.value; var product_id = document.getElementById(product_id).value; var quantity = document.getElementById(quantity).value; var sell_price = document.getElementById(sell_price).value; var price_mul = document.getElementById(price_mul).value; var qty_mul = document.getElementById(qty_mul).value; if(window.XMLHttpRequest) { // client use Firefox, Opera etc - Non Microsoft product try { MyHttpRequest = new XMLHttpRequest(); MyHttpRequest2 = new XMLHttpRequest(); MyHttpRequest3 = new XMLHttpRequest(); } catch(e) { MyHttpRequest = false; MyHttpRequest2 = false; MyHttpRequest3 = false; } } else if(window.ActiveXObject) { // client use Internet Explorer try { MyHttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); MyHttpRequest2 = new ActiveXObject("Msxml2.XMLHTTP"); MyHttpRequest3 = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { MyHttpRequest = new ActiveXObject("Microsoft.XMLHTTP"); MyHttpRequest2 = new ActiveXObject("Microsoft.XMLHTTP"); MyHttpRequest3 = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { MyHttpRequest = false; MyHttpRequest2 = false; MyHttpRequest3 = false; } } } else { MyHttpRequest = false; MyHttpRequest2 = false; MyHttpRequest3 = false; } if(MyHttpRequest) { // browser supports httprequest var query_string = '?product_id=' + product_id + '&quantity=' + quantity + '&sell_price=' + sell_price + '&customer_id=' + customer_id; MyHttpRequest.open("get", url_encode(file1 + query_string), true); // <-- run the httprequest using GET MyHttpRequest.onreadystatechange = function () { if(MyHttpRequest.readyState == 4) { // done and responded document.getElementById(target_div1).value = MyHttpRequest.responseText; // display result } else { document.getElementById(target_div1).value = MyHttpLoading; // still working } } MyHttpRequest.send(null); } else { document.getElementById(target_div1).value = ErrorMSG; // the browser was unable to create a httprequest } if(MyHttpRequest2) { // browser supports httprequest var query_string = '?product_id=' + product_id + '&quantity=' + quantity + '&sell_price=' + sell_price + '&price_mul=' + price_mul + '&customer_id=' + customer_id; MyHttpRequest2.open("get", url_encode(file2 + query_string), true); // <-- run the httprequest using GET MyHttpRequest2.onreadystatechange = function () { if(MyHttpRequest2.readyState == 4) { // done and responded document.getElementById(target_div2).value = MyHttpRequest2.responseText; // display result } else { document.getElementById(target_div2).value = MyHttpLoading; // still working } } MyHttpRequest2.send(null); } else { document.getElementById(target_div2).value = ErrorMSG; // the browser was unable to create a httprequest } if(MyHttpRequest3) { // browser supports httprequest var tqty = quantity * qty_mul; document.getElementById(target_div3).value = tqty; } else { document.getElementById(target_div3).value = ErrorMSG; // the browser was unable to create a httprequest } } function OrderRequest(target_div, file, target_div2, file2, target_div3, file3, target_div4, file4, check_div) { // get the branch selected var customer_id = document.AddOrder.customer_id.value; if (customer_id == 0) { alert("Please select the dealer first!"); document.AddOrder.customer_id.style.backgroundColor = "#FFFF00"; } else { var MyHttpRequest = false; var MyHttpRequest2 = false; var MyHttpRequest3 = false; var MyHttpRequest4 = false; var MyHttpLoading = 'Loading...'; var ErrorMSG = 'Sorry - No XMLHTTP support in your browser, buy a newspaper instead'; if(check_div) { var check_value = document.getElementById(check_div).value; } else { var check_value = ''; } if(window.XMLHttpRequest) { // client use Firefox, Opera etc - Non Microsoft product try { MyHttpRequest = new XMLHttpRequest(); MyHttpRequest2 = new XMLHttpRequest(); MyHttpRequest3 = new XMLHttpRequest(); MyHttpRequest4 = new XMLHttpRequest(); } catch(e) { MyHttpRequest = false; MyHttpRequest2 = false; MyHttpRequest3 = false; MyHttpRequest4 = false; } } else if(window.ActiveXObject) { // client use Internet Explorer try { MyHttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); MyHttpRequest2 = new ActiveXObject("Msxml2.XMLHTTP"); MyHttpRequest3 = new ActiveXObject("Msxml2.XMLHTTP"); MyHttpRequest4 = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { MyHttpRequest = new ActiveXObject("Microsoft.XMLHTTP"); MyHttpRequest2 = new ActiveXObject("Microsoft.XMLHTTP"); MyHttpRequest3 = new ActiveXObject("Microsoft.XMLHTTP"); MyHttpRequest4 = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { MyHttpRequest = false; MyHttpRequest2 = false; MyHttpRequest3 = false; MyHttpRequest4 = false; } } } else { MyHttpRequest = false; MyHttpRequest2 = false; MyHttpRequest3 = false; MyHttpRequest4 = false; } if(MyHttpRequest) { // browser supports httprequest var random = Math.random() * Date.parse(new Date()); // make a random string to prevent caching var file_array = file.split('.'); // prepare to check if we have a query string or a html/htm file if(file_array[1] == 'php') { // no query string, just calling a php file var query_string = '?rand=' + random; } else if(file_array[1] == 'htm' || file_array[1] == 'html') { // calling a htm or html file var query_string = ''; } else { // we have presumable a php file with a query string attached var query_string = check_value + '&customer_id=' + customer_id + '&rand=' + random; } MyHttpRequest.open("get", url_encode(file + query_string), true); // <-- run the httprequest using GET // handle the httprequest MyHttpRequest.onreadystatechange = function () { if(MyHttpRequest.readyState == 4) { // done and responded document.getElementById(target_div).value = MyHttpRequest.responseText; // display result } else { document.getElementById(target_div).value = MyHttpLoading; // still working } } MyHttpRequest.send(null); } else { document.getElementById(target_div).value = ErrorMSG; // the browser was unable to create a httprequest } if(MyHttpRequest2) // browser supports httprequest { var random = Math.random() * Date.parse(new Date()); // make a random string to prevent caching var file_array = file2.split('.'); // prepare to check if we have a query string or a html/htm file if(file_array[1] == 'php') // no query string, just calling a php file { var query_string = '?rand=' + random; } else if(file_array[1] == 'htm' || file_array[1] == 'html') // calling a htm or html file { var query_string = ''; } else // we have presumable a php file with a query string attached { var query_string = check_value + '&rand=' + random; } MyHttpRequest2.open("get", url_encode(file2 + query_string), true); // <-- run the httprequest using GET // handle the httprequest MyHttpRequest2.onreadystatechange = function () { if(MyHttpRequest2.readyState == 4) // done and responded { document.getElementById(target_div2).value = MyHttpRequest2.responseText; // display result } else { document.getElementById(target_div2).value = MyHttpLoading; // still working } } MyHttpRequest2.send(null); } else { document.getElementById(target_div2).value = ErrorMSG; // the browser was unable to create a httprequest } if(MyHttpRequest3) // browser supports httprequest { var random = Math.random() * Date.parse(new Date()); // make a random string to prevent caching var file_array = file3.split('.'); // prepare to check if we have a query string or a html/htm file if(file_array[1] == 'php') // no query string, just calling a php file { var query_string = '?rand=' + random; } else if(file_array[1] == 'htm' || file_array[1] == 'html') // calling a htm or html file { var query_string = ''; } else // we have presumable a php file with a query string attached { var query_string = check_value + '&rand=' + random; } MyHttpRequest3.open("get", url_encode(file3 + query_string), true); // <-- run the httprequest using GET // handle the httprequest MyHttpRequest3.onreadystatechange = function () { if(MyHttpRequest3.readyState == 4) // done and responded { document.getElementById(target_div3).value = MyHttpRequest3.responseText; // display result } else { document.getElementById(target_div3).value = MyHttpLoading; // still working } } MyHttpRequest3.send(null); } else { document.getElementById(target_div3).value = ErrorMSG; // the browser was unable to create a httprequest } if(MyHttpRequest4) // browser supports httprequest { var random = Math.random() * Date.parse(new Date()); // make a random string to prevent caching var file_array = file4.split('.'); // prepare to check if we have a query string or a html/htm file if(file_array[1] == 'php') // no query string, just calling a php file { var query_string = '?rand=' + random; } else if(file_array[1] == 'htm' || file_array[1] == 'html') // calling a htm or html file { var query_string = ''; } else // we have presumable a php file with a query string attached { var query_string = check_value + '&rand=' + random; } MyHttpRequest4.open("get", url_encode(file4 + query_string), true); // <-- run the httprequest using GET // handle the httprequest MyHttpRequest4.onreadystatechange = function () { if(MyHttpRequest4.readyState == 4) // done and responded { document.getElementById(target_div4).value = MyHttpRequest4.responseText; // display result } else { document.getElementById(target_div4).value = MyHttpLoading; // still working } } MyHttpRequest4.send(null); } else { document.getElementById(target_div4).value = ErrorMSG; // the browser was unable to create a httprequest } } } function getOrderTPrice() { var tquantity1 = +document.AddOrder.tquantity1.value; var tquantity2 = +document.AddOrder.tquantity2.value; var tquantity3 = +document.AddOrder.tquantity3.value; var tquantity4 = +document.AddOrder.tquantity4.value; var tquantity5 = +document.AddOrder.tquantity5.value; var tquantity6 = +document.AddOrder.tquantity6.value; var tquantity7 = +document.AddOrder.tquantity7.value; var tquantity8 = +document.AddOrder.tquantity8.value; var tquantity9 = +document.AddOrder.tquantity9.value; var tquantity10 = +document.AddOrder.tquantity10.value; var net_price1 = +document.AddOrder.net_price1.value; var net_price2 = +document.AddOrder.net_price2.value; var net_price3 = +document.AddOrder.net_price3.value; var net_price4 = +document.AddOrder.net_price4.value; var net_price5 = +document.AddOrder.net_price5.value; var net_price6 = +document.AddOrder.net_price6.value; var net_price7 = +document.AddOrder.net_price7.value; var net_price8 = +document.AddOrder.net_price8.value; var net_price9 = +document.AddOrder.net_price9.value; var net_price10 = +document.AddOrder.net_price10.value; var tqty = (tquantity1 * 1) + (tquantity2 * 1) + (tquantity3 * 1) + (tquantity4 * 1) + (tquantity5 * 1) + (tquantity6 * 1) + (tquantity7 * 1) + (tquantity8 * 1) + (tquantity9 * 1) + (tquantity10 * 1); var tnet_price = (net_price1 * 1) + (net_price2 * 1) + (net_price3 * 1) + (net_price4 * 1) + (net_price5 * 1) + (net_price6 * 1) + (net_price7 * 1) + (net_price8 * 1) + (net_price9 * 1) + (net_price10 * 1); document.AddOrder.tqty.value = tqty; document.AddOrder.tnet_price.value = tnet_price; } The problem is that the net price and line total are sometimes correct but sometimes incorrect. I really dont know where is the problem. Please give me insights. A million thanks. Quote Link to comment https://forums.phpfreaks.com/topic/240068-inconsistent-javascript-output/ Share on other sites More sharing options...
Adam Posted June 22, 2011 Share Posted June 22, 2011 Can you be a little more specific with the issue? Perhaps directions to recreate the issue at that website too? You've thrown a vague problem at us with a chunk of code and expected a solution. I can't speak for everyone, but I don't want to waste time trying to find out what the issue actually is, before I can even offer any help trying to find the cause of it. Quote Link to comment https://forums.phpfreaks.com/topic/240068-inconsistent-javascript-output/#findComment-1233210 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.