I'd like to populate a 'Full Name' field automatically with what the user types into the 'First Name' and 'Last Name' fields, so if they type 'John' and 'Smith' into the first and last name fields, the 'Full Name' field would be dynamically populated with 'John Smith'.
I'm not very good with jQuery so have only managed to populate the field with the 'First Name' so far after searching through other examples.
My current code is below, and any help on this would be appreciated.
<script>
$(document).ready(function(){
$('#first_name').keyup(function () {
$('#full_name').val(this.value);
});
});
</script>
<input type="text" name="full_name" id="full_name" value="" />
<input type="text" name="first_name" id="first_name" value="" />
<input type="text" name="last_name" id="last_name" value="" />
Thanks,
Ste
This should work
$('#first_name').keyup(function(){
$('#full_name').val(this.value+' '+$('#last_name').val());
});
$('#last_name').keyup(function(){
$('#full_name').val($('#first_name').val()+' '+this.value);
});
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