views:

196

answers:

1

Has anyone used jquery to take data from one form field and put it into another? I'm trying to create a form that when one text input is filled out a second is auto-populated with the first letter of the word that is in the first text input. I'm thinking I can limit the second text input to one character to help get the desired result, but I'm not having luck getting jquery to get the second text input and auto-populate once the first is entered. Here is the code I'm using:

<script type="text/javascript"> 
    jQuery(document).ready(function($) {
    $('#textBox1').keyup(function(){
    if($.trim($('#textBox2').val()) == '')
       $('#textBox2').val($(this).val().substring(0, 1);
});
});
</script>

Also, do I need to have any in the text input fields of the form other than matching "textBox1" id/names? Any suggestions?

+1  A: 
$('#textBox2').val($(this).val().substring(0, 1);
$('#textBox2').val($(this).val().substring(0, 1));

You were missing a parenthesis

nc3b
Perfect, thanks.
Jon