My HTML file:
<html>
<head>
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="js/scripts.js"></script>
<link rel="stylesheet" type="text/css" href="style.css" />
<title>
Login
</title>
</head>
<body>
<div class=loginForm>
<p>Worker-ID:<input type=text id=workerID name=workerID /></p>
<p>Password:<input type=password id=workerPassword name=workerPassword /></p>
<input type=submit id=submitLogin name=submitLogin value="Log in"/>
</div>
</body>
</html>
My scripts.js:
$('#workerID').keyup(function() {
alert('key up');
);
It doesn't work at all. I tried everything space,one letter, numbers. The alert doesn't show up. Where is the mistake?
You're missing the curly bracket to close the function:
Errors like these are usually seen in the browser's JavaScript console.
Syntax is wrong see here
change
);
to});
Apart from a typo around your missing
}
, when yourscript.js
file runs (in the<head>
section), the rest of your document does not exist. The easiest way to work around this is to wrap your script in a document ready handler, egAlternatively, you could move your script to the bottom of the document, eg
or use event delegation which allows you to bind events to a parent element (or the document), eg
in HTML
inser id, name,vale in
" "
in js
demo