SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    167
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Use return value in new function

    How can I use the return value from prev_picked() in my ajax call?

    Code JavaScript:
    function autosuggest_results (info)
    {		
    	if (info.length > 1)
    	{	
    		show();
    		prev_picked();
     
    		var with_field		= document.getElementById('users');
    		var with_auto		= document.getElementById('with_auto');
    		var users_list		= document.getElementsByName('with_username[]');
     
    		if(users_list.length == 0)
    		{
    			ajax.post('/assets/ajax/pm_autosuggest.php', 'info=' + info, function(resp)
    			{		
    				var search 	= eval('(' + resp + ')');
     
    				fill_list(search);
    			});
    		}
    		else 
    		{
    			ajax.post('/assets/ajax/pm_autosuggest.php', 'info=' + info + '&list=' + with_u_list, function(resp)
    			{		
    				var search 	= eval('(' + resp + ')');
     
    				fill_list(search);
    			});
    		}
    	}
    }
     
    function prev_picked ()
    {
     
    	var users_list		= document.getElementsByName('with_username[]');
    	var with_u_list 	= '';
     
    	if(users_list.length > 0)
    	{					
    		for(var j=0;j<=users_list.length; j++)
    		{
    			if(users_list[j] != undefined)
    			{
    				if((users_list.length - j) > 1)
    				{
    					with_u_list += users_list[j].value + ',';
    				}
    				else
    				{
    					with_u_list += users_list[j].value;
    				}
    			}					
    		}
    	}
     
    	return with_u_list;
    }

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,183
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Simply set your function call as a var to capture the return value

    Code JavaScript:
    var value = prev_picked();
    Blog/Portfolio | Evolution Xtreme | DFG Design | DFG Hosting | CSS-Tricks | Stack Overflow | Paul Irish
    Having lame problems with your code? Let us help by using a jsFiddle


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •