javascript - Dynamically changing which button is pressed with "enter" -


i have form 2 buttons , text inputs. default if press enter "click" first button. i'd make if type in either of text boxes, if press enter second button 1 clicked.

in simplified example below, pressing enter default "click" log in using facebook button. happen if entered in email or password text inputs. i'd if entered in either email or password inputs, pressing enter "click" login email/password button.

<form>     <button class="login-facebook">log in facebook</button>     <input type="text" class="email" placeholder="email"><br>     <input type="password" class="password" placeholder="password"><br>     <button class="login-password">log in email/password</button>    </form> 

goal like:

$('.email').add('.password').on('change', function() {     $('.login-password').settobenewdefaultclickifenterispressed();    }); 

where settobenewdefaultclickifenterispressed() changes default enter.

see: multiple submit buttons on html form – designate 1 button default

you can make them separate forms , play that. see also: preventdefault


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -