JSFiddle - React, Tailwind, and code Playground

HTML

<input id="text1" type="text" />
<input id="text2" type="text" />
<button id="test">Test</button>

JavaScript

$.fn.copyTo = function(selector) {
    $(selector).val($(this[0]).val().replace(/\s/g, "_"));
};

$(document).ready(function () {
    $("#test").click(function() {
        $("#text1").copyTo("#text2");
    });
});