Me, a HTML and JS newbie, has a simple piece of code that was almost literally copied from other answers when I was seeking for a solution for my problem (only changed the variables' names), yet it doesn't work in my case. The simplified version:
<!DOCTYPE html>
<html>
<head>
<title>my question</title>
<script src="/myScript.js"></script>
</head>
<body>
<form id="form1" action="#" method="post">
<input id="text1">
<input id="submit1" type="submit">
</form>
</body>
</html>
It does not alert()
neither if I write it like this:
// myScript.js
document.querySelector("form").addEventListener("submit", function() {
alert("test");
});
nor like this:
// myScript.js
document.querySelector("form").addEventListener("submit", myFunc);
function myFunc() {
alert("test");
}
I can't figure out how should I fix it.