Hey Guys,
I'm wanting to have one text field autopopulate with whatever the other text field has being typed into it.
How do I go about this?
Thank you! Hudson
Hey Guys,
I'm wanting to have one text field autopopulate with whatever the other text field has being typed into it.
How do I go about this?
Thank you! Hudson
Short and simple:
$('#idfield1').keypress(function() {
$('#idfield2').val($(this).val());
});
or to bind it to several events in order to update it also if it looses focus:
$('#idfield1').bind('keypress blur', function() {
$('#idfield2').val($(this).val());
});
Reference: .keypress(), .val(), .blur(), .bind()
Update:
Due to, for me, mysterious reasons, when the first character is typed in, it is not set in the other input field. Has anyone any idea? ;)
It works though by using keyup (keydown also produces the same strange result).
For an alternative:
$('#idfield1').bind('keyup keypress blur', function()
{
$('#idfield2')[0].value = $(this)[0].value;
});
or
$('#idfield1').bind('keyup keypress blur', function()
{
$('#idfield2').val($(this).val());
});