Skip to content Skip to sidebar Skip to footer

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:

<input type="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!)

function copy(what) {
  var copyText = document.getElementById(what);
  copyText.select();
  copyText.setSelectionRange(0, 99999)
  document.execCommand("copy");
 }
<textarea id="selectable">This is totally editable!</textarea>
<button onclick="copy('selectable')">Copy this !</button>
<br/>
<br/>
<textarea id="unselectable" readonly>This is not editable!</textarea>
<button onclick="copy('unselectable')">Copy this !</button>

Post a Comment for "How To Prevent User From Deleting Text In A Text Box"