The code below is colouring the input but not submitting the form in chrome. It’s working in Firefox:
<script type="text/javascript">
$(function(){
$('input').keypress(function(event) {
if (event.keyCode == '13') {
//alert($(this).parentsUntil('form').css('color'));
$('form').css('color','red');
$('form').submit();
}
});});</script>
Please note that the submit button is set to display:none, if I change it to visibility:hidden, it works but it reserve the place which is not what I want.
Thanks.
EDIT
Here’s a full example as requested below:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js"></script>
<title>دخول</title>
<script type="text/javascript">
$(function(){
$('input').keypress(function(event) {
if (event.keyCode == 13) {
$(this).parents('form').submit();
}
});
});
</script>
</head>
<body>
<form action="http://www.yahoo.com" method='post'>
<table >
<tr><td>name: </td><td><input type="text" name="username" value=""></td></tr>
<tr><td>password: </td><td><input type="password" name="password" value=""></td></tr>
<tr><td colspan=2><a href="javascript:void(0)" onclick="$('#loginfrm').click();">Login</a>
<div style="display: none;"><input type="submit" name="submit" value="Login" id="loginfrm"></div></td></tr>
</table>
</form>
your problem is that you named your submit button
submit, the browser sees that as a used name, give the submit button a name likedosubmitor whatever and it works.with name
submit(does not work)http://www.jsfiddle.net/pVUwW/
with name
dosubmit(works)http://www.jsfiddle.net/pVUwW/1/
the only difference in those is the name of the submit.
Other than that i changed the
event.keyCodetoevent.whichfrom your original code, see http://api.jquery.com/event.which/ for explanation why.