I am making a little forum and while trying to add the quote post functionality have come across a problem that has me stumped. Here is my js:

function addQuote(text)
	{
		var tArea = document.getElementById('forumReply_message');
		tArea.value = text;
	
	}

Here is sample HTML (one that doesn't work):

<a href="#replyArea" onclick="addQuote('Got a random playlist on right now.  All sorts of stuff... Miike Snow, Galactic, Danger Mouse, Bon Iver, Marlena Shaw, Dirty Projectors... it's eclectic to say the least.');">Quote</a>

I really can't figure out why this won't pass the addQuote() value into the textarea. It does work for some posts but most of them it doesn't. I appreciate any help.

Recommended Answers

All 4 Replies

If tArea is a <textarea> then .value won't work, you'll have to user innerHTML

I am making a little forum and while trying to add the quote post functionality have come across a problem that has me stumped. Here is my js:

function addQuote(text)
	{
		var tArea = document.getElementById('forumReply_message');
		tArea.value = text;
	
	}

Here is sample HTML (one that doesn't work):

<a href="#replyArea" onclick="addQuote('Got a random playlist on right now.  All sorts of stuff... Miike Snow, Galactic, Danger Mouse, Bon Iver, Marlena Shaw, Dirty Projectors... it's eclectic to say the least.');">Quote</a>

I really can't figure out why this won't pass the addQuote() value into the textarea. It does work for some posts but most of them it doesn't. I appreciate any help.

Are you sure? For one, why does it work some of the time? Secondly why does every single tutorial on the subject I have come across say that .value is the way to do this?

I will try out the .innerhtml and see how it works, but I am curious why .value works some of the time and not others.

You made a quote mistake:

<a href="#replyArea" onclick="addQuote('Got a random playlist on right now.  All sorts of stuff... Miike Snow, Galactic, Danger Mouse, Bon Iver, Marlena Shaw, Dirty Projectors... [B]it's [/B]eclectic to say the least.');">Quote</a>

Needs to be:

<a href="#replyArea" onclick="addQuote('Got a random playlist on right now.  All sorts of stuff... Miike Snow, Galactic, Danger Mouse, Bon Iver, Marlena Shaw, Dirty Projectors... it\'s eclectic to say the least.');">Quote</a>

With textarea's, the .value property does work. In fact, if the text contains \n's, and you use innerHTML to add the text into the textarea, it results into a weird error.

~G

Ah ha! I thought I ran that through PHP's htmlspecialchars with ENT_QUOTES on, looks like I'll have to look in to that a little more. Thanks for the help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.