Jump to content

Passing Var from function to function


Adamhumbug

Recommended Posts

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

Link to comment
Share on other sites

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)

		
	}
	

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.