简体   繁体   中英

copy several textboxes data into target textbox calling same function

I have several input textboxes with different id and class name. I want to track changes in any of the input textboxes, and reflect it into target textbox, but don't want to replicate the function for every individual textbox. Is it possible to use one function for all?

Appreciate your help

try something like this..........

  var finalValue ='';  

$('.textBoxesId').each(function(){
     $(this).change(function(){
       finalValue  = $(this).val();

    });
 });
   $('#targetID').val(finalValue  );

You can bind the change event for all the textboxes in the page using

$("input:text").change(function(){
    var textValue = this.value;
    $("#targetbox").val(textValue);
});

If the textboxes are inside a particular container then you can limit the search inside the container

$("#parentcontainer input:text").change(function(){
    var textValue = this.value;
    $("#targetbox").val(textValue);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM