2

I would like to load some text retrieved from a dB into a textarea. The user clicks a link:

<a class="editlink" id="<?php echo $review['id']; ?>" href="#"><?php echo $review['title']; ?></a>

JQuery passes the ID to GO.PHP:

$(".editlink").click(function() {
    $.get("go.php", {param: $(this).attr('id')}, 
        function(data) {
            $('textarea#area1').html(data);
        });    
    return false;
});

GO.PHP retrieves the text from the dB:

$qry = mysql_query("SELECT * FROM reviews WHERE id = ".$_GET['param']." "); 
while($review = mysql_fetch_array($qry)) {
    echo $review['description'];
} 

As confirmed by Firebug consolle, ID and the text are retrieved correctly. The probelm is that I'm not able to place the text into the textarea:

<textarea id="area1" rows="30" cols="55"></textarea>

I tried: .html(data), .text(data), .val(data) but none display anything. (Please note that the text in the dB may contain HTML tags that I would like to keep).

3 Answers 3

6

You need to set the text areas value.

$("#textareaID").val("value of text area");

I put this into a blank HTML doc referenced query in the head and it worked fine.

<form>
  <textarea id="test"></textarea>
</form>
<script>
    $('#test').val('testing');
</script>
Sign up to request clarification or add additional context in comments.

2 Comments

I did tried "$('textarea#area1').val(data);" but it does not display anything.
I did try your code, and it all worked for me. Since my answer was accepted did you fine the problem or did someone else accept it?
1

have you tried this

$('textarea#area1').attr('value',data);

2 Comments

Hi, I don't really understand. What's 'value'? 'data' is go to be filled by "echo $review['description'];" and, as said, Firebug consolle returns that the output is corrent. So what's 'value'?
check this post. may be of some help. stackoverflow.com/questions/415602/…
0

I tried: .html(data), .text(data), .val(data) but none display anything.

As other answers have stated, .val(data) or .text(data) should work. Don't .html(data) with textarea, because won't work in internet explorer however, as it will remove html when used with textareas (try this in IE). I would use the firebug console to ensure data is set, and look at your net tab to ensure everything is returning correctly. My guess is there is an error elsewhere.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.