Has anyone used javascript/ajax 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 finding the javascript to get the second text input to auto-populate from the first. Any suggestions?
A:
This seems like it would be pretty easy to do in jQuery.
$('#textBox1').keyup(function()
{
if($.trim($('#textBox2').val()) == '')
$('#textBox2').val($(this).val().substring(0, 1);
});
Tejs
2010-05-30 15:03:53
Thanks, I tried jquery, but I'm still not having any luck. Do I need to put something in the form field other than name or id?
Jon
2010-05-30 15:58:23
A:
Thanks, I just tried:
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#textBox1').keyup(function(){
if($.trim($('#textBox2').val()) == '')
$('#textBox2').val($(this).val().substring(0, 1);
});
});
</script>
But it isn't working for me. Do I need to put something in the form field other than name or id?
Jon
2010-05-30 15:21:44
Are you using a javascript library that might be interfering? I notice you are using jQuery() for the ready event, but not for the child selectors.
Tejs
2010-05-31 01:12:04