I have a simple txt input field:
<input type="text" name="" value="http://google.com" />
If i click inside the input, i want to select the text. This part is fine with this:
$('input.highlight').click(function(){
$(this).focus().select();
return false;
});
But, i want to disable the editing also. If i put a return false; to the keydown event, the ctrl+c is not working. If i put disabled="disabled" to the input, the select is not working.
Any idea? Thanks.
You can either use the readonly or the disabled attribute. Note that when disabled, the input's value will not be submitted when submitting the form. Also It's important to remind that even using readonly attribute, you should never trust user input which includes form submissions.
The readonly attribute makes a form control non-editable (or “read only”). A read-only field can't be modified, but, unlike disabled , you can tab into it, highlight it, and copy its contents.
You want to add the readonly attribute instead of disabled:
<input type="text" name="" readonly="readonly" value="http://google.com" />
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