How to replace linear channels / carriage return when pasted into input element (e.g. google)

I want line breaks to be replaced by spaces when an insert operation is performed on an input element (text).

For example, if the following text is inserted in a Google search:

foo
bar

it inserts like:

foo bar

By default, text input elements will stop at the first line break as follows:

foo

I managed to find a solution with the textarea element using the following code:

$("#textarea_element").bind('paste', function(e) {
    var el = $(this);
    setTimeout(function() {
        $(el).val($(el).val().replace(/(\r\n|\n|\r)/gm," "));
    }, 100);
});

But I would like to have this functionality on an input element . Any ideas?

+5
source share

No one has answered this question yet.


All Articles