I am trying to remove the onClick tags in my html and add an EventListener to my external js-file instead, but can't seem to get it to work.
The following lines work:
<input type="text" name="text" id="test">
<input type="submit" name="send" value="Skicka" id="klick" onclick="skriv()">
When removing onclick and adding the following to my javascript, it does not :
document.getElementById("klick").addEventListener("click", skriv);
function skriv() {
var input = document.getElementById("test").value;
alert("Hello" + " " + input);
}
Entire html:
<html>
<head>
<link rel="stylesheet" type="text/css" href="hello.css">
<title>
Multimedia
</title>
</head>
<body>
<script type="text/javascript" src="hello.js"></script>
<div>
<form>
<p>Skriv ditt namn:</p><br>
<input type="text" name="text" id="test">
<input type="submit" name="send" value="Skicka" id="klick">
</form>
<p class="lol">
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do"`enter code here`
</p>
</div>
</body>
</html>