Reputation: 93
I have a basic text area. I need a javascript function that will write a word ( i.e. #default ) into this textarea and will make ONLY this word not editable. The rest of the textarea should remain writable as normal. Only the words defined via javascript should not be editable by the user. Is there a way to do it that will work on IE7as well?
Thanks for the support.
Upvotes: 3
Views: 543
Reputation: 12197
You can try adding text-indent
to the textarea and then giving absolute position to the hashtag. I'm not sure it's going to work in IE7, but here's an example that works in Chrome and Firefox: http://jsfiddle.net/c5ZKk/
HTML:
<div class="hashtag">#hashtag</div>
<textarea>editable text</textarea>
CSS:
body, textarea {
font: 14px/1.5 Arial, sans-serif;
}
.hashtag {
position: absolute;
color: #aaa;
margin: 6px 0 0 5px;
}
textarea {
margin: 0;
padding: 5px;
text-indent: 62px;
width: 300px;
height: 200px;
}
Upvotes: 1