views:

41

answers:

1

I´ve got this javascript:

<a href="javascript:addtext('q');">q</a>

When it is clicked it writes text on a textarea.

I went through the encoding and found can do things like this:

This will add a " " (Space)

<a href="javascript:addtext('%20');">Space</a>

And this will add an "á"

<a href="javascript:addtext('&aacute;');">á</a>

Now I want to know how to add the return value. (enter)

As far as I know this are URL encondings so maybe you cant tu the enter value couse it makes no sense, but I´m just guessing?

Any ideas or workarounds appreciated!

Thanks in advance!

Trufa

+2  A: 

use

<a href="#" onClick="addtext('&aacute;');return false">á</a>

and

<a href="#" onClick="addtext('\n');return false">Linefeed</a>

or

<a href="#" onClick="addtext('%0D%0A');return false">CRLF</a>

The reason for not using the javascript: protocol is that some browsers actually unload the page when you do not return false on an onClick. It is possible to do javascript:void(somejavascript()) to achieve the same thing, but that will give a 404 if the user has turned JS off. Not a huge issue in your app which only works if JS is on, but onClick and return false is the canonical way. I would actually put the return false as the last statement in function addText, and do onClick="return addtext(...)" instead.

mplungjan
<a href="javascript:addtext('\n');">Return</a> and <a href="#" onClick=addtext('\n');return false">Return</a> Both work perfect!!! Thank you very much did you recommend onClick for anything in particular? Where can I get a complete reference??? Thanks agains
Trufa
Please look at my edit! Thanks :)
Trufa
Please see my edit too.
mplungjan
https://developer.mozilla.org/en/JavaScript and http://msdn.microsoft.com/en-us/library/yek4tbz0%28VS.94%29.aspx
mplungjan