I'm trying to make a working JS function which ought to add some text from argument to textarea, without erasing it's content.
<textarea id="message" name="message" cols="48" rows="4" accesskey="m"></textarea>
So the code above is a code of my textarea. And the script below should add some text to its value but it doesn't work.
function appendpostid( postid ) {
$('#message').val($('#message').val() + postid);
}
And, if it's important, here is the code that calls that function:
<a href="javascript:void(0)" onclick="appendpostid('."'>>".$rpl["id"]."'".')">'.$rpl["id"].'</a>
Code from generated page:
<a href="javascript:void(0)" onclick="appendpostid('>>69')">69</a>
开发者_运维技巧
What am I doing wrong? Thanks in advance!
Your code works: http://jsfiddle.net/d4pKt.
Also make sure that the function is not inside the jquery .ready or it doesn't work
I'm not sure a textarea has a value attached to it that you can manipulate. Please try:
function appendpostid( postid ) {
$('#message').append(postid);
}
精彩评论