Yevgeniy Bagackiy Yevgeniy Bagackiy - 1 month ago 6
Javascript Question

How to update same input with javascript

I have to droppable area with same name, I need input for each to save it then in different places. The problem is its just creating new input after clicking save button but I need to update already existing input and creating new one.
You can see sample here
I am using this function to create input for each of the boxes. in my work it can be even more than 2. It depends on user's input:

var LISTOBJ = {
saveList: function() {
$(".projLeader").each(function() {
var listCSV = [];
$(this).find("li").each(function(){
listCSV.push($(this).text());
});
var values = listCSV.join(', ');
$(".output").append("<input type='text' name='projLeader[]' value='"+values+"' /></br>");
console.debug(listCSV);
});
}
}

Answer

You can try below code, might be help you.

        var LISTOBJ = {
        saveList: function() {
          $(".output").html("");
            $(".projLeader").each(function() {
              var listCSV = [];
              $(this).find("li").each(function(){
                  listCSV.push($(this).text());
              });
              var values = listCSV.join(', ');
              $(".output").append("<input type='text' name='projLeader[]' value='"+values+"' /></br>");
                  console.debug(listCSV);                     

            });
          }
        }