I need to do a simple homework where you enter two integers in two text fields of a form and then you compute the sum and you print it in a "text field (not editable)". My program seems to work but it prints the right output and immediately reload the page. I want the page to remain with the printed output if the user does not click again on "submit" button
Here is my code HTML & JS :
function updateExpr() {
    var x1 = document.getElementById("n1").value;
    var x2 = document.getElementById("n2").value;
    var sum = +x1 + +x2;
    document.getElementById("sum").innerHTML = +x1 + +x2;
}<!DOCTYPE html>
<html>
<head>
    <title>Number in a form</title>
    <link href="mystyle.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="function.js">
    </script>
</head>
<body>
    <div id="mainDiv">
        <H3>Insert two positive numbers</H3>
         <form>
            First number:<br>
            <input id="n1" type="text" name="firstname"><br>
            Second number:<br>
            <input id="n2" type="text" name="lastname">
            <BR>
            <input type="submit" value="Submit" onClick="updateExpr()"/><BR><BR>
        </form> 
        The sum is:<br>
            <output id="sum" name="x" for="a b"></output>
    </div>
    <noscript>
        Sorry: Your browser does not support or has disabled javascript
    </noscript>
</body>
</html> 
     
     
     
     
     
    