select content field input [type="search"]

0

I would like a type="search" field to select its content when it is clicked. Currently to change a value in a search field you must double click to select the value that contains the field. What I need is for you to do the same when you take the focus or click.

<label  class="col-md-1  control-label "  >Inicio:</label>
 <input type="text" " type="text"   class="form-control datepicker input-sm "  >
		
  </div>
	
   
    
asked by Lorenzo Martín 06.12.2018 в 13:49
source

2 answers

2

To select the content you have to use the .select() function that usually works well with native javascript.

example using jQuery with the code fragment you passed:

$("input[type='text']").on("click", function () {
   $(this).select();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label  class="col-md-1  control-label "  >Inicio:</label>
 <input type="text" type="text" class="form-control datepicker input-sm "  >

I hope it helps you.

    
answered by 06.12.2018 / 14:10
source
2

You can do it with jQuery, in the following way:

$('#datepicker').on('click', function() {
  $(this).select();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
  <label class="col-md-1 control-label">Inicio:</label>
  <input id="datepicker" type="text" class="form-control datepicker input-sm" value="Texto" />
</div>
    
answered by 06.12.2018 в 14:08