textbox focus out

41,342

Solution 1

I have tried all the answers and not worked in all the browsers. And I combined all together in to it.

  1. TextBox.readonly = true;

OnFocus:

  1. var curText = TextBox.value; TextBox.value = ""; TextBox.value = curText;

  2. TextBox.blur();

  3. TextBox_Parent.focus()

And its working fine in all the browsers

Solution 2

I wonder what's the purpose of using a textbox in this case if the user can never write anything inside. Just add a disabled="disabled" attribute or readonly="readonly" (in case you want to post the value).

Solution 3

In HTML:

<input type="text" onfocus="this.blur();" />

In JS:

document.getElementById("input1").onfocus = function () { this.blur(); }

Some elements cannot accept focus without being editable.

Solution 4

Where is the point in that? JS would be (didn't test it):

$('#textbox').focusin(function() {
   $(this).focusout();
});
Share:
41,342
Santhosh
Author by

Santhosh

I'm so eager to learn new stuff's and to work in cutting edge technologies. I have around 4 years of experience in various technologies like Java, Asp.Net MVC, Javascript frameworks.

Updated on October 07, 2020

Comments

  • Santhosh
    Santhosh over 3 years

    I need to focus out from the textbox when it focus in.

    I try to set focus for outer div and its working fine in IE but not in mozilla.

    How do I do this?

    This is my current code:

    <div id="outer"> <input type = "textbox" /></div> Onfocus: document.getElementById("outer").focus()
    
  • E. van der Spoel
    E. van der Spoel almost 6 years
    This code includes JQuery. The question is about vanilla javascript.