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 text box and paste the code in Orkut scrapbook which will generate a imagine.
I am 开发者_C百科using onclick so when user clicks on code it highlight it and then they can copy.
The problems is that you can delete or remove text from within box, if your not careful.
I DONT want the user to be able to delete code in text box. How can I prevent this from happening without removing the onclick scrip.
Please if you could when reply maybe include the sample code above and highlight the new added code so I can see where to make my changes.
I hope I explained this well for anyone to understand!
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" >
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>
精彩评论