using a class to multiply numbers javascript code example
Example 1: javascript how to multiply numbers
<main>
<label for="firstNum">Number 1:</label>
<input type="number" id="firstNum" name="firstNum">
<label for="secondNum">Number 2:</label>
<input type="number" id="secondNum" name="secondNum"></br></br>
<button onclick="multiply()">Multiply</button></br></br>
<label for="result">Result</label>
<input type="number" id="result" name="result"/>
</main>
<script>
function multiply(){
num1 = document.getElementById("firstNum").value;
num2 = document.getElementById("secondNum").value;
result = num1 * num2;
document.getElementById("result").value = result;
}
</script>
Example 2: calculate two number and diplay next field without reload the page javascript
<p>Enter First Number :</p>
<br>
<input type="text" id="Text1" name="TextBox1" oninput="add_number()">
<br> <p>Enter Second Number :</p>
<br>
<input type="text" id="Text2" name="TextBox2" oninput="add_number()">
<br>Result :
<br>
<input type="text" id="txtresult" name="TextBox3">