I am attempting to automatically replace input from a HTML textarea for specific phrases (for example “a” with “asdf”). My code below works for HTML input boxes, but does not work for textarea. Is there a way to fix it for textarea?
HTML:
JavaScript
x
2
1
<textarea name = "text_input" type="text" id = "text_input"> </textarea>
2
JS:
JavaScript
1
6
1
$('body').on('input', 'textarea[name=text_input]', function() {
2
3
$(this).val($(this).val().replace('a', 'asdf'));
4
5
});
6
Advertisement
Answer
JavaScript
1
4
1
$('body').on('input', 'textarea[name=text_input]', function() {
2
$(this).val($(this).val().replace('a', 'asdf'));
3
});
4