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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -