Home > Software engineering >  Replace Textarea Input With JQuery
Replace Textarea Input With JQuery

Time:12-21

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:

<textarea name = "text_input" type="text" id = "text_input"> </textarea>

JS:

$('body').on('input', 'textarea[name=text_input]', function() {

    $(this).val($(this).val().replace('a', 'asdf'));

});

CodePudding user response:

$('body').on('input', 'textarea[name=text_input]', function() {
    $(this).val($(this).val().replace('a', 'asdf'));
});
  • Related