Skip to content Skip to sidebar Skip to footer

Write In A Form By Clicking On A Button

I have a button that when clicked reveals a form. The user then has to click the form to begin typing. I would like to make it so that when the user clicks the 'click here' button

Solution 1:

Definitely possible. You are looking for the .focus() method on the textbox. I have included it in my answer below:

$("#button1").click(function(){
	$(".form").show();
        $("#form1").focus(); // IMPORTANT
});
.form {
display:none;
}
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divclass="form"><inputid="form1"type="text"placeholder="type here"/></div><buttonid="button1">click here</button>

Solution 2:

Using the focus method to change the cursor focus, this solution will wait for the animation to complete then have the focus change.

$("#button1").click(function(){
    $(".form").show(function() {
        $("#form1").focus();
    });
});
.form {
display:none;
}
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divclass="form"><inputid="form1"type="text"placeholder="type here"/></div><buttonid="button1">click here</button>

Post a Comment for "Write In A Form By Clicking On A Button"