views:

259

answers:

5
+1  Q: 

textbox focus out

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 to do this.

+2  A: 

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).

Darin Dimitrov
+1  A: 

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

$('#textbox').focusin(function() {
   $(this).focusout();
});
Felix Kling
+1  A: 

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.

Andy E
A: 

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

santose
A: 
/*for textarea*/
$(document).ready(function() {
$('textarea[type="text"]').addClass("idleField");
$('textarea[type="text"]').focus(function() {
    $(this).removeClass("idleField").addClass("focusField");
    if (this.value == this.defaultValue){
        this.value = '';
    }
    if(this.value != this.defaultValue){
        this.select();
    }
});
$('textarea[type="text"]').blur(function() {
    $(this).removeClass("focusField").addClass("idleField");
    if ($.trim(this.value == '')){
        this.value = (this.defaultValue ? this.defaultValue : '');
    }
});

});

that's what I used on my form.

vette982