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.
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.
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).
Where is the point in that? JS would be (didn't test it):
$('#textbox').focusin(function() {
$(this).focusout();
});
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.
I have tried all the answers and not worked in all the browsers. And I combined all together in to it.
OnFocus:
var curText = TextBox.value; TextBox.value = ""; TextBox.value = curText;
TextBox.blur();
And its working fine in all the browsers
/*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.