Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove focus from textbox?

When opening form the cursor is waiting in the text box along with help text.So there are some validation error happening. So i don't want focus when opening form, user have to click the text and type the text. But here didn't any onfocus eventhough cursor in the textbox .

if(!$.trim($("#productsTextArea1").val())){
        helpTip = "help string ....";
        $("#productsTextArea1").val(helpTip);
        $("#productsTextArea1").css("color","#999");
        $("#productsTextArea1").click(function(event){
            if($("#productsTextArea1").val().indexOf("Enter a return")>-1){
                $("#productsTextArea1").css("color","black").val("");
            }
        });
    } else {
         $("#productsTextArea1").blur();
    }

Please advise...

JSFIDDLE

like image 363
user2444474 Avatar asked Jul 15 '13 18:07

user2444474


1 Answers

UPDATE:

Use HTML5 Placeholder attribute, you don't need to use any js.

    <textarea id="productsTextArea1" name="product" rows="5" 
placeholder="Some Hint Text is Placed Here"></textarea>

To disable autofocus on all input elements use this.

  $(function(){
        $('input').blur();
    });

To disbale autofocus on a particular element, pass the element id as below:

$(function(){
    $('input#someid').blur();
});
like image 96
defau1t Avatar answered Sep 27 '22 16:09

defau1t