After reading this post here in Stackoverflow, (Detect the Enter key in an text input field) I tried to make a few of my inputs fire on enter... I did not work. I made a simple example and it still doesn't work. Can someone hint as to the proper way? (FYI - Definitely a newbie here)
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>On Enter</title>
<script src="../../Scripts/jquery-2.1.0.min.js"></script>
<script>
$(".input1").keyup(function (e) {
if (e.keyCode == 13) {
alert ("It Works");
}
});
</script>
</head>
<body>
<input type="text"
id="input1"
placeholder="Press Enter When Done">
</input>
</body>
</html>
Thanks
First you need to say
#input1
other than.input1
, then run it when the entire DOM is ready:Edit: As @jfriend00 mentioned in a comment it's a good idea to use
e.which
other thane.keycode
. To do so you can change:e.keyCode == 13
toe.which == 13
. This way is recommenced by the people at jQuery, as it normalizese.keyCode
ande.charCode
.