Focus in the text box

I need to focus in the text box when it is focused.

I am trying to set focus for an external div and its work in IE, but not in mozilla.

How to do it?

This is my current code:

<div id="outer"> <input type = "textbox" /></div> Onfocus: document.getElementById("outer").focus()
+3
source share
5 answers

I tried all the answers and did not work in all browsers. And I combined them together.

  • TextBox.readonly = true;

OnFocus:

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

  2. TextBox.blur();

  3. TextBox_Parent.focus()

And its performance in all browsers

+1
source

I wonder what is the point of using a text field in this case, if the user cannot write anything inside. Just add the attribute disabled="disabled"or readonly="readonly"(in case you want to publish this value).

+5

HTML:

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

JS:

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

, .

+3

? JS ( ):

$('#textbox').focusin(function() {
   $(this).focusout();
});
+1
/*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 I used in my form.

0
source

Source: https://habr.com/ru/post/1731191/


All Articles