Alex Rivera | Logout

Textarea not getting updated text in jQuery

Asked 2011-08-25T15:02:55.967
12

So I have a razor view:

@{
    int i=1;
    foreach(var story in Model.Storylines)
    {
        <span style="float:left;">Storyline @i</span> <span style="float:right; margin-right:5px;">Character Count: @story.CharCount</span><br /><br />
        <textarea id=@("entry"+@i) rows="5" style="width:730px; overflow:auto;">@story.Description</textarea><br /><br />
        i++;
    }
}

So the textarea with id entry1 has a description like "this is a story" when the page initially loads. Once I type something into that text area, and then hit a button whose only function is:

alert($("#entry1").text());

I still get "this is a story". Why isn't the textarea being updated with the text that I've typed in?

Edit
Report

1 Answer

6

You will want to use .val() as opposed to .text(), as that is how to access the content of a <textarea>:

alert($("#entry1").text());

should be:

alert($("#entry1").val());
answered 2011-08-25T15:04:57.560

Your Answer