How To Prevent User From Deleting Text In A Text Box
Ok so I am new here and was wondering if someone a little more advance then me can help me out. I have text box on my website with code for user(s) to copy the code that's in the
Solution 1:
You can add readonly="readonly" to your textbox tag. Example:
<input type="text" name="someNAme"readonly="readonly" >
you can also try with:
<inputtype="text" name="someNAme" disabled="disabled" >
Solution 2:
Here is a totally editable textbox, and a not editable textbox. The difference is that in the second textbox, there is a readonly
attribute, which prevents the user from editing the text. (Run the code snippet!)
functioncopy(what) {
var copyText = document.getElementById(what);
copyText.select();
copyText.setSelectionRange(0, 99999)
document.execCommand("copy");
}
<textareaid="selectable">This is totally editable!</textarea><buttononclick="copy('selectable')">Copy this !</button><br/><br/><textareaid="unselectable"readonly>This is not editable!</textarea><buttononclick="copy('unselectable')">Copy this !</button>
Post a Comment for "How To Prevent User From Deleting Text In A Text Box"