Is there an easy way to populate one form field with duplicate content from another form field?
Maybe using jQuery or javascript?
You just have to assign the field values:
// plain JavaScript
var first = document.getElementById('firstFieldId'),
second = document.getElementById('secondFieldId');
second.value = first.value;
// Using jQuery
$('#secondFieldId').val($('#firstFieldId').val());
And if you want to update the content of the second field live, you could use the change
or keyup
events to update the second field:
first.onkeyup = function () { // or first.onchange
second.value = first.value;
};
With jQuery:
$('#firstFieldId').keyup(function () {
$('#secondFieldId').val(this.value);
});
Check a simple example here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With