I have a textarea within an iframe. I want to select the textarea text with an onclick event in JavaScript.
Example:
I have an iframe.
The inner content of the iframe is this:
<textarea id="textarea" disabled onclick="selectthis()">
"content of textarea"
</textarea>
I want to select the text so the user can copy it:
I put this at the head of my page:
function selectthis() {
document.getElementById('textarea').select();
}
But when I click on the textarea, it’s not selected.
You typed
getElementByIdwrong.Change
getelementByIdtogetElementById. JavaScript is case-sensitive.Plus,
UPDATE
I see what you did there. You can not select text within a disabled
<textarea>.See http://jsfiddle.net/DerekL/ArGhg/2/
According to Francisc’s comment, using
readonlywill solve the problem.See http://jsfiddle.net/DerekL/ArGhg/3/