0

I am trying to submit the login on pressing the Enter key, earlier everything was under a form tag so it would work on pressing the Enter key. But now it won't, could someone please give me a fix for this.

HTML:

<div class="login-form">
    <p>Please Sign In</p>
    <div class="form-group" id="login-fields">
        <div class="cols-sm-10">
            <div class="input-group">
                <span class="input-group-addon"><i class="fa fa-user fa" aria-hidden="true"><span class="text--white glyphicon glyphicon-user"></span></i>
                </span>
                <input type="text" name="user" id="user" placeholder="Username" class="form-control" required/>
            </div>
        </div>
    </div>
    <div class="form-group" id="login-fields">
        <div class="cols-sm-10">
            <div class="input-group">
                <span class="input-group-addon"><i class="fa fa-user fa" aria-hidden="true"><span class="text--white glyphicon glyphicon-lock"></span></i>
                </span>
                <input type="password" name="pass" id="pass" placeholder="Password" class="form-control" required/>
            </div>
        </div>
    </div>
    <div>
        <input type="submit" value="Sign In" id="submit-login" onclick="save()" />
    </div>
</div>
</div>
Bob
  • 467
  • 6
  • 25
  • 2
    If you want it do behave like a form with a default action, why not put it back in a form tag? – Barbara Laird Feb 02 '17 at 23:19
  • I have an ajax PUT request call to this login form, earlier when I had the form tag it would default the method='post' and not recognize PUT method. After I removed the form tag it works well. So had to remove it – Bob Feb 02 '17 at 23:23
  • Thank you @MikeMcCaughan, I will try the solution on that link and get back, seems like it is the possible solution. – Bob Feb 02 '17 at 23:26
  • @MikeMcCaughan I marked this duplicate as per your suggestion and the solution did help me. Thank you again cheers – Bob Feb 02 '17 at 23:43

1 Answers1

1

Did you try to put a form tag arround it and bind an eventlistener to it:

document.querySelector('.myForm').addEventListener('submit', function(e) {
  e.preventDefault();
  // do your put request here
}
cyr_x
  • 13,987
  • 2
  • 32
  • 46