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.
Answer: Use the jQuery val() Method You can simply use the jQuery val() method to set the value of an input text box.
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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With