Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6892847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:35:08+00:00 2026-05-27T06:35:08+00:00

here is the code: HTML: <textarea data-bind=value: MyText> Hello world line 2 line 3

  • 0

here is the code:

HTML:

<textarea data-bind="value: MyText">
    Hello world
    line 2
    line 3
</textarea>   

JS:

var viewModel = 
{
    MyText : ko.observable()  
};
ko.applyBindings(viewModel);   

http://jsfiddle.net/HSfuq/

Textarea becomes empty, because of ko.observable(), but how can I save existing value in textarea?

I have big multiline document in textarea (from database), and I want to edit it with features of Knockoutjs.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:35:09+00:00Added an answer on May 27, 2026 at 6:35 am

    Don’t extract the text from HTML, just make your view model like this:

    var viewModel = {
    
        MyText : ko.observable("I'm the data from the server")  
    
    };
    
    ko.applyBindings(viewModel);    
    

    http://jsfiddle.net/HSfuq/1/
    I would prefer the first method.

    Or you can extract the text from the html like this, if you must do so:

    HTML:

    <textarea data-bind="value: MyText" id='textareaID'>
        Hello world
        line 2
        line 3
    </textarea>  
    

    JS:

    //using jQuery, but you could do this otherwise as well 
    var texareaText = $('#textareaID').text();
    var viewModel = {
    
        MyText : ko.observable( texareaText )  
    
    };
    
    ko.applyBindings(viewModel);  
    

    http://jsfiddle.net/HSfuq/2/

    Or use JSON serialization (any way you like, return JSON(yourDataIncludingMultiLineText); from MVC controller action, or a serializer library like Newtonsoft JSON.net http://nuget.org/List/Packages/Newtonsoft.Json) to serialize the multi line text.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code <html> <body> <?php echo <b>Hello World</b> <br />; ?> </body>
how to replace selected text in html textarea? mardagz to [b]mardagz[\b] here's my code
Here is a part of my html code (video urls marked with a django-template
Here is an old add in to quickly comment out HTML code. Maybe I
I have this html code that i want to edit with jQuery. Here is
I am trying to test some of these code here http://ha.ckers.org/xss.html on my code.
I'm seeing my Friend's code here... <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0 Transitional//EN> <HTML>
Here's what I'm trying to do, simplified: <input rel=TimeStart> // bunch of HTML code
not sure why I find this so difficult. Here is the html code: <tr>
Here is my code: $('#right').load('textes.html #nicolas'); $('#right').load('textes.html #antoine'); The problem is that the content

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.