Adamhumbug Posted August 26, 2020 Share Posted August 26, 2020 Hi All, I have a function: function existingTags(){ var plta = $('#peopleLinkedToArticle').val() window.taggedPeople = [plta] console.log(taggedPeople) } This console log shows the following which is correct. Array [ "11,2" ] I have a second function that needs to use tagged people function removeTaggedPeople(){ console.log(taggedPeople) var e = event.target $(e).attr('onclick','tagInArticle()') var taggedPerson = $(e).data('id') var i = 0; while (i < window.taggedPeople.length) { if (window.taggedPeople[i] === taggedPerson) { window.taggedPeople.splice(i, 1); } else { ++i; } } console.log(window.taggedPeople) var tp = window.taggedPeople.toString() $('#peopleLinkedToArticle').val(tp) $(e).remove() } The first console log in the second function which runs on a button click also shows Array [ "11,2" ] Ids are not being removed from this array and i cannot figure out why Quote Link to comment Share on other sites More sharing options...
Adamhumbug Posted August 26, 2020 Author Share Posted August 26, 2020 Apologies, this is mis-titled Quote Link to comment Share on other sites More sharing options...
Adamhumbug Posted August 26, 2020 Author Share Posted August 26, 2020 I think the issue is that the values going into the array are strings not integers. I used this to solve my problem function existingTags(){ var plta = $('#peopleLinkedToArticle').val() plta = plta.split(',') taggedPeople = plta for (a in taggedPeople ) { taggedPeople[a] = parseInt(taggedPeople[a], 10); } console.log(taggedPeople) } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.