Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript - unfocus a textbox

Tags:

javascript

I have a mobile template with a login form which is ajax / url hash based browsing. If on an iphone a user clicks the "go" button on the iphone keyboard the ajax authenticates / logs them in and then loads the next page inside another div and hides the current login form div.

The problem is, on an iphone the keyboard is still popped up. Is there anyway to unfocus a textbox element via javascript?

like image 636
Joe Avatar asked Nov 02 '10 05:11

Joe


People also ask

How do you Unfocus an element in JavaScript?

Use the blur() method to remove the focus from an element, e.g. input. blur() . If you need to remove the focus from the currently active element without selecting it, call the blur method on the activeElement property - document.

How to lose focus from textbox in JavaScript?

Use HTML5 Placeholder attribute, you don't need to use any js. To disable autofocus on all input elements use this. Actually there is no autofocus, what are you asking.

How do you Unfocus an element in HTML?

The HTMLElement. blur() method removes keyboard focus from the current element.

How to remove focus on element?

The blur() method removes focus from an element.


2 Answers

This is what I used when .blur() didn't want to be my friend

function blurAll(){  var tmp = document.createElement("input");  document.body.appendChild(tmp);  tmp.focus();  document.body.removeChild(tmp); } 
like image 35
shygoo Avatar answered Oct 20 '22 09:10

shygoo


Use the blur() method or try setting the focus on another element like a link.

like image 57
Xint0 Avatar answered Oct 20 '22 09:10

Xint0