Facebook
From Morose Partdridge, 8 Years ago, written in HTML5.
This paste is a reply to JS Form from Adrian - view diff
Embed
Download Paste or View Raw
Hits: 492
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.     <meta charset="UTF-8">
  4.     <title>Form</title>
  5. </head>
  6.     <script>
  7.         function add(x1, x2) {
  8.             var form = document.getElementById("myForm");
  9.             form.submit();
  10.             x1 = parseFloat(form.x1.value);
  11.             x2 = parseFloat(form.x2.value);
  12.             result = x1 + x2;
  13.             alert('Wynik dodawania: ' + result.toFixed(2));
  14.         }
  15.        
  16.         function sub(x1, x2) {
  17.             var form = document.getElementById("myForm");
  18.             form.submit();
  19.             x1 = parseFloat(form.x1.value);
  20.             x2 = parseFloat(form.x2.value);
  21.             result = x1 - x2;
  22.             alert('Wynik odejmowania: ' + result.toFixed(2));
  23.         }
  24.     </script>
  25.    
  26.     <form id="myForm">
  27.         <label for="x1">Podaj pierwszą liczbę:</label>
  28.         <input size="20" name="x1">
  29.         <label for="x2">Podaj drugą liczbę:</label>
  30.         <input size="20" name="x2">
  31.         <input type="button" value="Dodaj" onclick="add();">
  32.         <input type="button" value="Odejmij" onclick="sub();">
  33.     </form>
  34. </body>
  35. </html>
  36.  
  37.