javascript - Populating div in real time with form input data - Stack Overflow

I have a form (just one field) which I am populating with some data. I would like to get me Div contain

I have a form (just one field) which I am populating with some data. I would like to get me Div container populated with the data I put there in a real time. So no refresh, after I type in some text in the form field, I get it in the div as well. Does anybody know how to do it? JQuery, AJAX?Any advice appreciated.

I have a form (just one field) which I am populating with some data. I would like to get me Div container populated with the data I put there in a real time. So no refresh, after I type in some text in the form field, I get it in the div as well. Does anybody know how to do it? JQuery, AJAX?Any advice appreciated.

Share Improve this question asked Jun 28, 2011 at 0:07 VonderVonder 4,05915 gold badges46 silver badges63 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5
var div = $('div')[0];

$('input').bind('keyup change', function() {
    div.innerHTML = this.value;
});

Try it out: http://jsfiddle/H6P2z/

Of course you should make the selectors specific to your actual elements.

With jQuery you can do this very easily:

$('#textFieldId').bind('change', function (event, previousText) {
    $('#divId').html($(this).val());
});

You could bind an onkeyup event to the input field. When the event fires, you can grab the contents of the field and do what you want with it.

This might look like this:

$(selector).keyup(function(e) {
   // find the value of the field
   var text = $(this).val();

   // do something with it
   $(yourDivSelector).html(text);
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744614027a4583938.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信