Code:
<script language="JavaScript">
language is deprecated; type is required.You omitted the var keyword. If you intend to create globals, please create them in the global scope.
Code:
document.write("The answer is ", c);
You can't document.write() after the page has loaded without destroying the current page. Also, document.write() accepts only one argument.
Code:
<script type="text/javascript">
function apple() {
var a = 2,
b = 2,
c = a + b;
document.getElementById("apple_op").firstChild.nodeValue = "The answer is " + c;
return false;
}
</script>
</head>
<body>
<h1>Calculate</h1>
<p id="apple_op"> </p>
<form action="" onsubmit="return apple();">
<input type="submit" value="Calculate">
</form>
</body>
Bookmarks