remove value from the running list using jquery

erikTsomik
erikTsomik used Ask the Experts™
on
I have a 2 running list that a stored in the hidden form variable. 1 is to keep selected items another is to keep deleted items. When i click on delete icon i need to remove the item from the first list and add it to the second list. Addition piece is working .

I have a code for deletion  but it does not work

var newrID = 'r' + ID;
                  var list = $('#' + newrID).val();
                  var index = list.indexOf(ID2);
                  alert(list);
                  alert(list.indexOf(bodyID));
                  $("#" + newrID).val(list).find(ID2).remove();
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
IT Expert
Top Expert 2009
Commented:
You are assuming list is a jQuery object. It is just a string.

You did not show you add so I cannot see if you use commas or what.

Perhaps you mean this:

 $("#" + newrID).val(list.replace(ID2,""))
erikTsomikSystem Architect, CF programmer

Author

Commented:
My Add is here

var newdID = 'd' + ID;
                  var curr_relID = $("#" + newdID).val();
                  curr_relID = curr_relID.split(",");
                  curr_relID.push(ID2);
                  $("#" + newdID).val(curr_relID.join(","));
Michel PlungjanIT Expert
Top Expert 2009

Commented:
Then my code is
 $("#" + newrID).val(list.replace(","+ID2,""));

Or split, loop and delete item then join if array not empty

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial