Not Setting Focus To Text Field In Firefox
I faced a very interesting issue. I'm trying to set the focus on a input field using Javascript (no jQuery, I tried that also but not worked) using window.onLoad. Just take a look
Solution 1:
Try adding a slight delay:
functiononloadFocus(){
setTimeout(function() {
document.getElementById('name').focus()
}, 10);
}
Solution 2:
You must wrap the function-call into a function, otherwise it will be called immediately, not onLoad(the input is still unknown at this time):
window.onload=function(){onloadFocus();}
Solution 3:
you should use window.onload=onloadFocus;
instead of window.onload=onloadFocus();
because in case of window.onload=onloadFocus();
onloadFocus will run immediately and at that time input field may not be available.
Solution 4:
I got the solution for it. If you want to focus in Firefox. Write the focus function at the starting of the script tag.
<scripttype="text/javascript">document.getElementById('name').focus();
// rest of the code here.</script>
Hope this will help you.
Post a Comment for "Not Setting Focus To Text Field In Firefox"