Fill in second input when typing in first

Asked

Viewed 518 times

-3

I have an html form with SOCIAL REASON and FANTASY NAME, so I wanted that when typed in the field "Social Reason" the field "Fantasy Name" was filled automatically with the same value. Thanks in advance for the help.

2 answers

2

You can do this with jquery using something like this:

$(document).on('keyup', '#razao-social', function() {
    $('#nome-fantasia').val($(this).val());
});
  • Friend thanks for the help, sorry my very little knowledge in Javascript, as I would put this in my form?

1

$(document).ready(function() {
    $('#ID_CONTROLE_RAZAO_SOCIAL').on('keyup', function() {
        $('#ID_CONTROLE_NOME_FANTASIA').val($(this).val());
    });
});

Put this snippet of code in any Script tag, and preferably before the end of the Body tag, remembering to replace the controls ID’s name.

  • Guys, thanks for your help. At first it didn’t work, then I checked that my input only had the property name="" and it didn’t have the id (Javascript takes the ID) so I added the ID with the same name and it worked!! remembering to add the <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> no head! Thanks for your help Cayo and Ives

Browser other questions tagged

You are not signed in. Login or sign up in order to post.