The problem is only happening in Internet Explorer. In any other browser I can submit the form by hitting enter on my keyboard, in IE8 I have to actually click the button.
I searched around for fixes for a while and found a few things but it’s still not working. The javascript I’m using should be looking for keycode 13, which is enter, but when I hit enter the field clears itself without submitting the form and the keycode is not triggered. The keycode thing only returns results for letters and not for shift/enter.
Here’s the HTML my current solution:
<form action="chatscreen.php" name="loginform" method="post">
<p>Please enter your name to continue:</p>
<label for="name">Name:</label>
<input type="text" name="name" id="name" onkeyup="whichButton("loginform","enter")"/>
<button type="submit" name="enter" id="enter" value="Enter">Button</button>
</form>
And here’s the javascript I tried to implement as a fix:
<script type="text/javascript">
function whichButton(formname,elementname) {
alert("got a key = " + event.keyCode);
if (event.keyCode === 13) {
var followingInput = document.getElementById(elementname);
document.formname.elementname.click();
}
}
</script>
1 Answer