javascript - Focus the first input on load only if no input is focused -
i'm trying set default focus pages of site without changing focus on page reload.
i mean:
- user opens page.
- focus automatically set on 1st input.
- user changes focus 3rd input.
- user refreshes page.
- focus must not change 1st input again. (this requirement fail accomplish).
my current code follows:
$(document).ready(function() { if($(':focus').length === 0) { $(':input:not([type="hidden"]):first').focus(); } });
the condition true every time!
$(document).ready({ window.onload=function(){ if(session.storage.getitem("text3")){//if key= text3 set,then change focus 3rd text box. $('#your3rdtextid').focus(); } $('#your3rdtextid').focus(function(){ session.storaage.setitem("text3","selected")//here set key text3 , value selected later use. }); });
you can provide own custom conditions.this small example.hope helped you.good luck project.
Comments
Post a Comment