I am trying to add some predefined text (actually html) to a text area on submit. It's important that the predefined text precede the existing text when combined. I don't know a lot about javascript. I just piece stuff together. After some research here is some code I put together. function changeText() { var addtext = "<img src="" />"; var extext = document.forms[0].getElementsByTagName("textarea")[0].value; var newtext = addtext + extext; document.forms[0].getElementsByTagName("textarea")[0].value = newtext; } Code (markup): This "should" : 1) Set the predefined text. (addtext) 2) Get the existing text in the text area. (extext) 3) Combine the predefined text and the existing text. (newtext) 4) Change the textarea value to the new combined text. How would I call that and then get the form to submit? Thanks.
I am working on an addon for firefox, so all this is to modify a form on a page that's not mine. The form on the page doesn't have onsubmit defined, so how would I inject that with javascript? document.forms[0].onsubmit="changeText(); return true;"; Code (markup): ??
try: document.forms[0].onsubmit=function() { var addtext = "<img src='' />"; var extext = document.forms[0].getElementsByTagName("textarea")[0].value; var newtext = addtext + extext; document.forms[0].getElementsByTagName("textarea")[0].value = newtext; return true; } Code (markup):