I'm new to JS, and I'm trying to make a very simple program that will take an input and produce a relevant output. However, I'm doing something wrong, as it's not working. Here is my code.
<html>
<head>
<title>Test</title>
<h1>Test</h1>
</head>
<body>
<p>Please type your input into the box below.</p>
<input type="number"; id="input">
<button type="submit"; onclick="Output()">Submit</button>
<pre id="OutputHere">Type an input first!</pre>
<script type="text/javascript">
window.onload = function {
if(document.getElementById("input").boolValue != null); {
Output();
}
}
function Output() {
var input = document.getElementById("input").value
switch(input) {
case 1:
document.getElementById("OutputHere").value="4"
case 2:
document.getElementById("OutputHere").value="9"
}
}
I agree with the problems that the other answers pointed out. I also would suggest using
addEventListener
in your JavaScript instead of setting theonclick
tag in your HTML.If it helps, I've restructured your code a bit below.