javascript - jQuery will not update textarea -


i have html textarea defined in index.html defined follows:

<textarea id="mytextarea" rows="12" readonly="7" class="form-control"></textarea> 

i have javascript file named shared.js. right now, shared.js has following:

function appendtotextarea(id, text, stayoncurrentline) {     var current = $(id).val();      var newtext = current + ' ' + text;     if (!stayoncurrentline) {         newstatus += '\n';               }     $(id).val(newtext);      console.log($(id).val());    } 

index.html referencing shared.js. calls appendtotextarea fine. i'm calling code function in index.html called mybuttonclick.

function mybuttonclick() {     appendtotextarea('#mytextarea', 'hello', false);     appendtotextarea('#mytextarea', 'how', false);     appendtotextarea('#mytextarea', 'are', false);     appendtotextarea('#mytextarea', 'you', false); } 

when above called, text of mytextarea never updated. however, in console, see no errors. in addition, can see text how expect it. doing wrong?

define newstatus empty string , concatenate outputted string:

function appendtotextarea(id, text, stayoncurrentline) {     var current = $(id).val();     var newstatus = "";     var newtext = current + ' ' + text;     if (!stayoncurrentline) {         newstatus += '\n';     }     $(id).val(newtext + newstatus);      console.log($(id).val()); } 

-jsfiddle-


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -