Advertisement
Shailrshah

AJAX addition

Apr 23rd, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.03 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <script>
  5.         function addJS() {
  6.             var a = document.getElementById("aj").value;
  7.             var b = document.getElementById("bj").value;
  8.             document.getElementById('cj').value = Number(a) + Number(b);
  9.         }
  10.         function showSum() {
  11.             var a = Number(document.getElementById("a").value);
  12.             var b = Number(document.getElementById("b").value);
  13.  
  14.             var xmlhttp=new XMLHttpRequest();
  15.             xmlhttp.onreadystatechange = function() {
  16.                
  17.                     document.getElementById('c').value=xmlhttp.responseText;
  18.             }
  19.             xmlhttp.open("GET","d1.php?a="+a+"&&b="+b, true);
  20.             xmlhttp.send();
  21.         }
  22.     </script>
  23. </head>
  24. <body>
  25.    
  26. <form>
  27.     <input type="number" id="a" onchange="showSum()" /> +
  28.     <input type="number" id="b" onchange="showSum()" /> =
  29.     <input type="number" id="c" />
  30. </form>
  31. <form>
  32.     <input type="number" id="aj" /> +
  33.     <input type="number" id="bj" /> =
  34.     <input type="number" id="cj" />
  35.     <input type="button" value="JS" onclick="addJS()" />
  36. </form>
  37. </body>
  38. </html>
  39.  
  40.  
  41. <?php echo $_REQUEST["a"]+$_REQUEST["b"]; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement