I have some javascript that lets user select items from one bucket and move to a second bucket. The first bucket are possible choices minus those selected. The second bucket is the selection and each item gets a row in the table. The second time a user does this, however, I would like to save as follows: If the selection is new, add a new record. If a selection has been deleted, delete the old record. If the selection is unchanged, leave it unchanged.
Concrete example.
At beginning
1,4,5 in first bucket
2,3 in second bucket
(This implies someone previously selected 2 and 3. Rows exist for 2 and 3 in a table.
After selection
1,2,5 in first bucket
3,4 in second bucket.
(The users has kept 3 in the 2nd bucket, but dropped 2 and added four. I want to keep row for 3, delete row 2 and add new row4.
Someone suggested I use JS to figure out what rows to keep, add or delete, but this has proven beyond my limited JS abilities.
Conceptuatlly would imagine it would be something like (pseudocode)...
var 2array = 3,4;
var 1array = 2,3;
var addarray = "";
var delarray = "";
foreach val as 2array{
if val in 1array {
//ignore
}
else
{
addarray = addarray+val
}
}
for each val as 1array {
if val in 2array {
ignore
}
else {
del array =delarray+val
}
}
or something to that effect.
Thanks for any suggestions!
!=
indent code propertly – Gabriel Santos May 11 '12 at 18:25