Satch3000 Satch3000 - 5 months ago 8
jQuery Question

Synchonise 2 input fields, can it be done using jQuery?

Can jQuery synchronise or copy the text of one input field to another when input A is modified? For example:

<input id="input_A" type="text" /> ...If I type something here

<input id="input_B" type="text" /> ... It will be copied here


Can jQuery Do this?

Answer

Try this:

$("#input_A").bind("keyup paste", function() {
    $("#input_B").val($(this).val());
});

For jQuery 1.7+ use on:

$("#input_A").on("keyup paste", function() {
    $("#input_B").val($(this).val());
});

Example fiddle

Comments