javascript - prevent focus from leaving form fields -
in app, have login form this
<div id="container"> <form name="login" id="login" method="post" action=""> <input name="email" type="text" class="label" id="email" placeholder="enter email..."> <input name="password" type="password" class="label" id="password" placeholder="enter password..."> <input type="submit" name="submit" id="submit" value="login"> <a href="register.html" class="sign">sign up</a> </form> </div>
on touch devices, when tap screen, focus leaves form fields (input,button,links). happens on blackberry , android devices, haven't tried on iphone.
how can prevent focus leaving form fields? i'm building app phonegap.
i don't think can prevent user clicking/selecting else, can return focus whenever looses it. simplest case:
<input onblur="this.focus()" type="text" name="text1"/>
but can lock user forever input unless replace function evaluates if current input still needs focus reason , otherwise not trigger focus again.
if problem when user scroll page, can try this:
<script type="text/javascript"> var last_selected_input; window.onscroll = function () { if (last_selected_input) { last_selected_input.focus(); } } </script> <input type="text" name="text1" onfocus="last_selected_input = this" />
but need clear variable last_selected_focus
whenever field complete avoid persistent focus on each page scroll.
Comments
Post a Comment