Please excuse me if this is a newbie question. I am new to thi开发者_C百科s.
I would like that a user fill out a form with their info and, just before clicking submit, there to be a summary of details area where they confirm their details are correctly entered.
So is it possible for me to "bind" specific inputs to specific spans or divs and as they type (or maybe onBlur?) the span would reflect what is written in the respective input???
Populate div with id somediv
with whatever is typed the input with id inputid
each time a key is pressed:
$('#inputid').keyup(function() {
$('#somediv').html($(this).val());
});
$('#myFormField').bind('change', function(){
$('#myTargetSpan').text($(this).val());
});
Two most obvious possibilities
Use jQuery Data Link plug-in that is able to bind input elements to other elements or even to JavaScript objects. Either a one-way or a two-way link can be established.
or
Use this code to update
div
on each keystroke
$("#YourInputID").keyup(function(){ $("#YourDivID").text(this.value); });
when user leaves input
$("#YourInputID").blur(function(){ $("#YourDivID").text(this.value); });
精彩评论