Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Put fixed text on an input text box

Tags:

html

css

How can I put default text in an HTML text input element which the user can't delete (fixed text at the start of the input).

The second thing what I want is that the cursor will be positioned after this fixed text.

like image 608
Brahim Avatar asked Apr 26 '13 09:04

Brahim


People also ask

How do you fix input box value?

Answer: Use the jQuery val() Method You can simply use the jQuery val() method to set the value of an input text box.


1 Answers

var requiredText = 'https://';
$('#site').on('input', function() {
  if (String($(this).val()).indexOf(requiredText) == -1) {
    $(this).val(requiredText);
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="site" />
like image 95
Eduardo de Souza Avatar answered Oct 28 '22 07:10

Eduardo de Souza