Wednesday 24 May 2017

Update Price Value

index.php

<html>
   <head>
  <title>Ajax Multiply Example</title>
    </head>
   <body>
  <h1 align="center"><font color="#000080">Online shopping</font></h1>
  <form name="f1">
<strong>Item</strong>&nbsp;&nbsp;<strong>Qty</strong>&nbsp;&nbsp;
<strong>Price</strong>&nbsp;&nbsp;<strong>Subtotal</strong>
<hr>
<?php
$cnt=mysql_connect("localhost","root","");
$s=mysql_select_db("shopping",$cnt);
$w=mysql_query("select * from total where item='samsung'");
while($r=mysql_fetch_array($w))
{  
?>
<strong><?php echo $r['item']; ?></strong>&nbsp;&nbsp;
<strong><input name="a" id="a" value="<?php echo $r['quantity']; ?>"
style="border:0px;width:30px;"></strong>
<strong><input name="b" id="b" value="<?php echo $r['price']; ?>"
style="border:0px;"></strong>
<b><input name="result"  id="result" value="<?php echo $r['subtotal']; ?>"
style="border:0px;margin-left:0px;"></b><br>
<strong></strong>&nbsp;&nbsp;<strong >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" value="change" onClick="callMultiply()" name="showmultiply"
style="border:0px solid red;background:#FFF;" id="save" ></strong>
<?php
}
?>
</form>
 </body>
</html>

style.css

  strong
  {
      margin-left:80px;
  }
  a hover:a
  {
      text-decoration:overline;
  }

valid.css

function postRequest(strURL){
       document.f1.showmultiply.value="save";
  var xmlHttp;
  if(window.XMLHttpRequest){ // For Mozilla, Safari, ...
   var xmlHttp = new XMLHttpRequest();
  }
  else if(window.ActiveXObject){ // For Internet Explorer
   var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlHttp.open('POST', strURL, true);
  xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  xmlHttp.onreadystatechange = function(){
   if (xmlHttp.readyState == 4){
    updatepage(xmlHttp.responseText);
   }
  }
  xmlHttp.send(strURL);
   }
   function updatepage(str){
  document.getElementById('result').value = str;
   }
  function callMultiply(){
  var a = parseInt(document.f1.a.value);
  var b = parseInt(document.f1.b.value);
  var url = "multiply.php?a=" + a + "&b=" + b + "";
  postRequest(url);
   }

Output:


--------------------------------------------------------------------------------------------------------------------------

No comments:

Post a Comment