What I want to do is get values from two forms and then add them and display the result, the problem is that it's not working and can't find out why. Is something simple but I'm new in Javascript =/. Here is my code
<!DOCTYPE html>
<html>
<head>
<title> Random Page </title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form>
Escriba el primer número: <input type="number" id="txtNumber1">
</form>
<br>
<form>
Escriba el segundo número: <input type="number" id="txtNumber2">
</form>
<br>
<button id="btnSumar" onclick="Sumar()"> ¡Sumar! </button>
<br>
<p id="p"> I'm a paragraph </p>
<script>
function Sumar() {
document.getElementById("p").innerHTML="It works until here.";
var num1 = document.getElementById("txtNumber1").value;
var num2 = document.getElementById("txtNumber2").value;
this.resultado = num1 + num2;
}
document.getElementById("p").innerHTML="The result is " + resultado;
</script>
</body>
</html>
Any help will be appreciated. Tahnks.