javascript - Form not submitting on ENTER when no type="submit" element present -


We are using custom buttons to submit forms. One click event is assigned to submit a related form on .btn-submit. However, & lt; Button type = "submit" & gt; or & lt; Input type = "submit" & gt; element & lt; Form & gt; , either the user name or password does not submit the form by pressing ENTER in the text field.

I still want users to type in a input < & lt; Form & gt;

HTML

  in the field without any  type = "submit"  code> & lt; Form action = "post.php" method = "post" & gt; & Lt; P & gt; & Lt; P & gt; Username & lt; / P & gt; & Lt; Input type = "text" name = "user name" style = "width: 300px; font-size: 18px" & gt; & Lt; / P & gt; & Lt; P & gt; & Lt; P & gt; Password & lt; / P & gt; & Lt; Input type = "password" name = "password" style = "width: 300px; font-size: 18px" & gt; & Lt; / P & gt; & Lt; Input type = "hidden" name = "user_login" value = "1" & gt; & Lt; Div class = "btn-inline btn-green btn-submit" & gt; Sign in & lt; / Div & gt; & Lt; / Form & gt;  

js

  $ (document) .ready (function () {$ ('.btn-submit'). ('Click', Function (e) {$ (this) .Parents ('Form: First'). Submit ();});});  

You can do something to do it when pressed inside the login key The input is activated by the submit button

  $ ('form'). Keypress (function (e) {var code = e.keyCode = e.which; if (code === 13) {E.preventDefault (); $ (".btn-submit"). Click ();} ;});   

Edit

This wont cause submit button is clicked if the return is pressed in textarea This will do the same for the text type of input s.

  $ ('input: text'). Keypress (function (e) {var code = E. kikode} E.e.; if (code === 13) {e.preventDefault (); $ (".btn-submit"). Click ();} ;});  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -