Jump to content

[SOLVED] Populate a textarea by clicking link


bluesoul

Recommended Posts

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.

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>

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!  ;D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.