QUESTION SOLVED. Thanks eicto!


Friends, help me figure it out, I'm completely confused

The function checks the login / password form. If login> = 3 characters and focus on this form, then when you press Enter or Tab, the flipform () function should start

There are no errors in the console, flipform () itself works flawlessly. But when you press Enter or Tab, flipform () always works only when exactly 3 characters are written in the login form. If more - for some reason, it works by double-clicking on Enter

I have no idea why such bizarre symptoms

$(function() { var login = $("input[id='frontloginform']"); var password = $("input[id='frontpasswordform']"); login.keyup(function(){ if (login.val().length>=3 && login.is(":focus")) { $("#enter").css("display", "block"); $(function(){ $("#frontloginform").keydown(function(e) { if (e.which == 13){ //password.focus(); - если раскомментировать, то двойного нажатия не получится, и совсем работать не будет flipform(); } else if (e.which == 9){ flipform(); } }); }); } else{ $("#enter").css("display", "none"); } }); password.keyup(function(){ if (password.val().length>5) { $("#secondenter").css("display", "block"); } else { $("#secondenter").css("display", "none"); } }); }); 
  • Thank you very much for your help! It all worked. About checking completely agree with you, but here is the design, the password form appears only after entering the login :) There are no buttons - silent-box
  • so the submit event for enter is called. - zb '
  • There is such a design that after typing three symbols it’s necessary to show the blinking Enter gif next to the form, so that the person will guess to press it after the end of the login set :) - silent-box

1 answer 1

A why do you have a block that hangs keydown on #frontloginform is inside the login.keyup handler? I think this will cause you to hang the keydown as many times as you press the buttons in the login (after the 3rd character). besides, the handler will not go anywhere if you reduce the length of the string to 2x. make a fiddle with markup and an example (albeit a simple flipform() )

Update

Yes, I'm telling you - hang the handler in this way - an error, what else is css animation?

Update

Than this does not suit you? But in general it is better not to do this check, but on the submit event (well, you can by switching the focus on the input)

  • Inside the keyup, I count the number of characters that are entered. A keydown - to track pressing Enter / Tab. Works on fiddle - jsfiddle.net/k3r5s. But the banal background change also works on the page, but css3 animation - with the above problems - silent- box
  • Updated Fiddle : jsfiddle.net/Hm4aX If you enter in the form "123" - it works immediately, if "1234" - only after double pressing Enter Ok, thanks, I will think how to hang it differently - silent-box