JQuery to bind input value to span or div?

Sorry if this is a newbie question. I am new to this.

I would like the user to fill out the form with his information and, before clicking "Submit", a summary of the information area will appear in which they confirm that their data is entered correctly.

So, is it possible for me to "bind" specific inputs to certain spans or divs, and as they are entered (or, perhaps, onBlur?) The range will reflect what is written on the corresponding input ???

+4
source share
3 answers

Fill the div with id somediv so that input is typed with id inputid each time a key is pressed:

 $('#inputid').keyup(function() { $('#somediv').html($(this).val()); }); 
+7
source
 $('#myFormField').bind('change', function(){ $('#myTargetSpan').text($(this).val()); }); 
+1
source

The two most obvious features

  • Use the jQuery Data Link plugin , which can associate input elements with other elements, or even JavaScript objects. One-way or two-way communication can be established.

    or

  • Use this code to update the div

    each time you press a key

     $("#YourInputID").keyup(function(){ $("#YourDivID").text(this.value); }); 

    when user exits input

     $("#YourInputID").blur(function(){ $("#YourDivID").text(this.value); }); 
0
source

Source: https://habr.com/ru/post/1339377/


All Articles