开发者

Using jQuery to auto-populate a form field from another form field [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

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开发者_如何学Python 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?


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

You were missing a parenthesis

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜