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. Link to comment https://forums.phpfreaks.com/topic/137271-solved-populate-a-textarea-by-clicking-link/ 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> Link to comment https://forums.phpfreaks.com/topic/137271-solved-populate-a-textarea-by-clicking-link/#findComment-717245 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> Link to comment https://forums.phpfreaks.com/topic/137271-solved-populate-a-textarea-by-clicking-link/#findComment-717258 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> Link to comment https://forums.phpfreaks.com/topic/137271-solved-populate-a-textarea-by-clicking-link/#findComment-717267 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! Link to comment https://forums.phpfreaks.com/topic/137271-solved-populate-a-textarea-by-clicking-link/#findComment-717824 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.