javascript - jquery function to replace textarea text not working -
i'm not used working jquery appreciated. have written function cannot work, can tell me wrong.
$(function() { $('#replace_button').onclick(function() { $('#box_txt').val().replace(/\t/g, '[tab]'); $('#box_txt').val().replace(/\n/g, '[break]'); }); });
the html accompanies is
<textarea name='box_txt' id='box_txt' rows='6' cols='50'></textarea> <br> <input type='button' id='replace_button' value='replace'>
i want replace tabs [tab] , linebreaks [break] when button pressed.
many thanks.
val
returns string, not kind of pointer value. , replace
doesn't change string pass (strings immutable in javascript) returns new one.
you may use
var field = $('#box_txt'), s = field.val(); s = s.replace(/\t/g, '[tab]').replace(/\n/g, '[break]'); field.val(s);
Comments
Post a Comment