Reputation: 4516
I have a <input type="text">
and if user clicks inside it I want to make the content (value) of that box selected. How would I do that?
Upvotes: 29
Views: 70192
Reputation: 193
You can try following jQuery
code which automatically call on page load
<script>
$(document).ready(function(){
$('input').each(function(){
$(this).click(function() {
this.select();
});
});
$("#return_date").focus();
});
</script>
Upvotes: 0
Reputation: 145458
Try select
method:
document.getElementById("myinput").onclick = function() {
this.select();
};
Upvotes: 4
Reputation: 13384
You can try following code inside a javaScript method, and call the method onClick event of the textbox...
function calledOnClick(){
document.getElementById('test').select();
}
Upvotes: 2