Salve, sto progettando una calcolatrice con JavaScript molto basilare (ho appena iniziato ad utilizzare questo linguaggio di programmazione) e dovrei far si che ogni volta che il calcolo venga eseguito i due campi dove inserisco i numeri si svuotino automaticamente. La calcolatrice è molto banale e va bene così, è possibile farlo?? Vi metto qui sotto il codice....
codice:<!DOCTYPE html> <html> <body> <h2>CALCULATOR</h2> <p>Please input two numbers</p> <input id="numb"> <button type="button" onclick="myFunction()">Submit</button> <p id="demo"></p> <script> function myFunction() { var x, text; // Get the value of the input field with id="numb" x = document.getElementById("numb").value; // If x is Not a Number or less than one or greater than 10 if (isNaN(x)) { text = "Input not valid"; } else { text = "Input OK"; } document.getElementById("demo").innerHTML = text; } </script> <input id="numb1"> <button type="button" onclick="myFunction1()">Submit</button> <p id="demo1"></p> <script> function myFunction1() { var x1, text1; // Get the value of the input field with id="numb" x1 = document.getElementById("numb").value; // If x is Not a Number or less than one or greater than 10 if (isNaN(x1)) { text = "Input not valid"; } else { text = "Input OK"; } document.getElementById("demo1").innerHTML = text; } </script> <button type="button" onclick="myFunction2()">+</button> <p id="demo2"></p> <script> function myFunction2() { var x,y,z; // Get the value of the input field with id="numb" x = document.getElementById("numb").value; y = document.getElementById("numb1").value; z = 0; // If x is Not a Number or less than one or greater than 10 if (isNaN(x)) { } else { z= (x + y); } document.getElementById("demo2").innerHTML = z; } </script> <button type="button" onclick="myFunction2()">-</button> <p id="demo2"></p> <script> function myFunction2() { var x,y,z; // Get the value of the input field with id="numb" x = document.getElementById("numb").value; y = document.getElementById("numb1").value; z = 0; // If x is Not a Number or less than one or greater than 10 if (isNaN(x)) { } else { z= (x - y); } document.getElementById("demo2").innerHTML = z; } </script> <button type="button" onclick="myFunction2()">*</button> <p id="demo2"></p> <script> function myFunction2() { var x,y,z; // Get the value of the input field with id="numb" x = document.getElementById("numb").value; y = document.getElementById("numb1").value; z = 0; // If x is Not a Number or less than one or greater than 10 if (isNaN(x)) { } else { z= (x * y); } document.getElementById("demo2").innerHTML = z; } </script> <button type="button" onclick="myFunction2()">/</button> <p id="demo2"></p> <script> function myFunction2() { var x,y,z; // Get the value of the input field with id="numb" x = document.getElementById("numb").value; y = document.getElementById("numb1").value; z = 0; // If x is Not a Number or less than one or greater than 10 if (isNaN(x)) { } else { z= (x / y); } document.getElementById("demo2").innerHTML = z; } </script> </body>

Rispondi quotando
