J
J
JS2015-12-13 19:57:53
JavaScript
JS, 2015-12-13 19:57:53

How to add code from html file to textarea using JavaScript(jQuery) or Node.js?

Hello!
How can I insert code from html file into textarea using JS? Or open this file, copy the code from there and also paste it with Node(fs)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kovalsky, 2015-12-13
@Johnnycus

With jQuery:

$( "#textarea" ).load( "url-of-file-to-load", function( response, status, xhr ) {
  if ( status == "error" ) alert( "Sorry but there was an error: " + xhr.status + " " + xhr.statusText );
  else $( this ).val(response);
});

As tef said , you can use the default fs for the node, everything is pretty simple there, no problems should arise.

T
tef, 2015-12-13
@tef

If you need to do it in a browser, google fileAPI. If node.js, then this is the fs module, which, if necessary, can be googled.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question