In a Rails applicat开发者_StackOverflow社区ion using prototype, I have the following (simplified) code in my view (Edit: replaced with actual HTML output):
<textarea cols="34" id="note" name="note" rows="5"></textarea>
<a href="#" onclick="$('note').update('test note'); return false;">copy note</a>
This works fine on a fresh page visit and does what is intended: Insert "test note" into the text area on clicking the link.
However, if I then remove or edit the text in the textarea field and click the link again, the text is not replaced again. This happens in both Safari and Firefox. No javascript errors are occurring.
Strangely enough, Firebug does show the text between the tags on these subsequent clicks being replaced again.
What am I missing?
EDIT:
I found this: http://scott-tabar-safari.blogspot.com/2008/01/prototype-v16-ajaxupdater-and-textarea.html. Addding a $('formid').reset() fixes this. Better solutions are still welcome.
You should be using the value
property of the textarea DOM object:
<a href="#" onclick="$('note').value = 'test note'; return false;">copy note</a>
精彩评论