I was trying to add the two operator using javascript and then I wished to try it in ajax then I wanted to see the difference between two codes action but whenever I implemented the addition in javascript I got stuck because thepage show the result for a sec then it redirect back. Can anyone please tell me what is the wrong with this code?
<!DOCTYPE html>
<html>
<head>
<title>ajax</title>
<script>
function loadFunction(){
//window.alert("hello");
var x= document.getElementById("d1");
var y =document.forms["myForm"]["op1"].value;
var z =document.forms["myForm"]["op2"].value;
x.innerHTML="<h2>" +(parseInt(y)+parseInt(z)) + "</h2>";
x.style.width="35%";
x.style.border="1px solid #050";
}
</script>
</head>
<body>
<form id="myForm" onsubmit="loadFunction()" method="POST">
<input type="text" id="op1" placeholder="operator 1" required></input> +
<input type="text" id="op2" placeholder="operator 2" required></input>
<button type="submit">show the result</button>
</form>
<div id="d1">
<h2>The summation will print here!!!</h2>
</div>
</body>
</html>