Reputation:
Form is not submitting on enter. Maybe I'm missing something so need help of fellows or any advise/tips to find out the problem. I think the problem is in password field. Thanks!
<form onsubmit="login(); return false;">
<p>
Email*: <input type="text" id="email" />
</p>
<p>
Password*: <input type="password" id="pass" />
</p>
<p>
<span id="loginBut" onclick="login(); return false;" class="btn bold">
Submit
</span>
</p>
</form>
function login() {
console.log('Inside login');
}
Upvotes: 0
Views: 212
Reputation:
<button class="btn bold" onclick="signup(); return false;">Submit </button>
Upvotes: 0
Reputation: 2206
it should be
<form id="myForm">
<p>
Email*: <input type="text" id="email"/>
</p>
<p>
Password*: <input type="password" id="pass"/>
</p>
<p>
<span id="loginBut" onclick="login();"
class="btn bold">Submit </span>
</p>
</form>
and your login
function should look like,
function login(){
document.getElementById("myForm").submit();
}
if you still want to use the span you can try adding this script.
document.getElementById('myForm').onkeypress = function(e){
//enter has the keyCOde 13
if (e.which == 13){
document.forms[0].submit();
}
};
Upvotes: 2
Reputation: 36511
Just to repeat the appropriate response @adeneo already said in the comments, your form definition should be:
onsubmit="return login()"
And your login
function should return true
when you want the form to submit
If you return false
, the form will not submit
Upvotes: 1