I'll start by saying I'm fairly new to javascript, jquery, and php. Although I'm more familiar with PHP than the other 2 I'm still just a beginner. So I'm trying to make this HTML form for work where people can submit short remarks.
My goal is that the people using it can switch between input boxes using enter but only the specific input boxes that have the same class. Otherwise, the form can be submitted by pressing enter. (no submit button will be present).
Here's my HTML (just a tryout, not the real thing yet)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> Help </title>
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$("input").bind("keydown", function(event) {
if (event.which === 13) {
alert("asd");
event.stopPropagation();
event.preventDefault();
$(':input:eq(' + ($(':input').index(this) + 1) +')').focus();
}
});
</script>
</head>
<body>
<h3> welcome to the help page </h3>
<form action= "Helppage.php" method="post" ">
<p><b> name: </b></br>
<input class= "code" type="text" name="name" size= "20" ></p>
<p><b> location: </b> </br>
<input class= "code" type= "text" name="location" size= "20" > </p>
<p><b> message:</b></br>
<input class= "code" type= "text" name="message"size= "20" ></p>
<p><b> remark:</b></br>
<input type= "text" name="remark"size= "20" ></p>
<p><b> department:</b></br>
<input type= "text" name="department"size= "20" ></p>
</form>
<h3> thanks for participating!!</h3>
</body>
</html>
I've already tried to find a solution. Like this one: How to use enter key to focus into next input and this: Activating next input field in form on enter
But for some reason, I can't seem to get any of them to work...
Thanks in advance!