This code will throw the default text back to the beginning of the text field if it does not appear after the user changes:
<script type="text/javascript"> function fixText() { var textAreaElement = document.getElementById("mytextarea"); var searchPhrase = "I like/dislike this site because"; if(textAreaElement) { if(textAreaElement.value.indexOf(searchPhrase) != 0) { textAreaElement.value = searchPhrase + " " + textAreaElement.value } } } </script> <textarea id="mytextarea" onblur="fixText();" onchange="fixText();">I like/dislike this site because</textarea>
I threw it together for only a minute or so, and it has some obvious flaws, such as the fact that if someone deletes only the UNACCEPTED text by default, they can get a strange result, for example: βI like / dislike this site because I like this site because itβs nice. " But I'm sure you can manipulate it to make it more efficient. Something like this might work in conjunction with the pimvdb answer.
I like Elian Ebbing's answer though, if your employer allows you to do it that way.
Joshua carmody
source share