Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
16
rated 0 times [  22] [ 6]  / answers: 1 / hits: 27046  / 13 Years ago, wed, july 20, 2011, 12:00:00

Is there a way in Javascript to forcibly disable text field autofocus on page load?



I know of the focus() method, but not how to disable it. My actual problem is that autofocusing in a modal window forces the window to appear with the scrollbar halfway down already and scrolled to the first input field, whereas I would like to disable this entirely.



Thanks!


More From » jquery

 Answers
6

You can use .blur() ,



var elelist = document.getElementsByTagName(input);
for(var i = 0; i < elelist.length; i++){
elelist[i].blur();
}


If you want to disable focus on all the textfields,



var elelist = document.getElementsByTagName(input);
for(var i = 0; i < elelist.length; i++){
elelist[i].addEventListener(focus, function(){
this.blur();
});
}

[#91096] Tuesday, July 19, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
payne

Total Points: 527
Total Questions: 108
Total Answers: 88

Location: Tajikistan
Member since Thu, Apr 14, 2022
2 Years ago
;