bluesoul Posted December 16, 2008 Share Posted December 16, 2008 Sorry for the possibly obscure working in the subject, not exactly sure the best way to describe it but I believe it's a fairly simple bit of JS. I have a <textarea> that starts with some standard text. I want to give my users some preset links that populate that textarea with some static data. They can be simple text links or buttons. Quote Link to comment Share on other sites More sharing options...
webster08 Posted December 17, 2008 Share Posted December 17, 2008 you can do it like this: <script type="text/javascript"> function addTxt(txt_content) { document.getElementById("mytxtarea").value = txt_content; return false; } </script> Quote Link to comment Share on other sites More sharing options...
bluesoul Posted December 17, 2008 Author Share Posted December 17, 2008 I feel like a schmuck but I'm not sure what to do with this. I've messed with it a little bit and I guess I'm not calling the function the right way. If the page loads with... <textarea name="foo">This is foo text.</textarea> And I want to click a link that says bar and have... <textarea name="foo">This is bar text.</textarea> Do I need to do something like... <script type="text/javascript"> function addTxt(txt_content) { document.getElementById("foo").value = txt_content; return false; } </script> <a href="#" onClick="javascript:addTxt(This is bar text.)">BAR</a> Quote Link to comment Share on other sites More sharing options...
webster08 Posted December 17, 2008 Share Posted December 17, 2008 do it like this: <script type="text/javascript"> function addTxt(txt_content) { document.getElementById("foo").value = txt_content; } </script> <textarea id="foo"></textarea><br><br> <a href="javascript:addTxt('This Is Bar Text')">Bar</a> Quote Link to comment Share on other sites More sharing options...
bluesoul Posted December 17, 2008 Author Share Posted December 17, 2008 do it like this: <script type="text/javascript"> function addTxt(txt_content) { document.getElementById("foo").value = txt_content; } </script> <textarea id="foo"></textarea><br><br> <a href="javascript:addTxt('This Is Bar Text')">Bar</a> Thanks, I figured out what was wrong (I gave the textarea a name but not an id). Great stuff, you've helped more than you know! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.