Current location: Hot Scripts Forums » General Web Coding » JavaScript » [SOLVED] Passing data between 2 functions.


[SOLVED] Passing data between 2 functions.

Reply
  #1 (permalink)  
Old 03-30-06, 09:01 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
[SOLVED] Passing data between 2 functions.

Here's my code:

Code:
function Notification(action, cat) 
	{	
		http.open('post', 'multimedia.php');
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http.onreadystatechange = HandleNotifiaction;
		http.send('action='+ action +'&cat='+ cat +'&method=ajax');
		
		return false;
	}
	
	function HandleNotifiaction() 
	{	
		if (http.readyState == 1)
		{ 
			document.getElementById('video').innerHTML = "Please wait, loading..." ; 
		} 
		else if (http.readyState == 4 && http.status == 200)
		{
			var response = http.responseText;
			
			document.getElementById('video').innerHTML = response;
		}
	}
This works so far. Now what I want to do is to pass the variable "cat" to the "HandleNotifiaction" function. I tried this

Notification()
Code:
http.onreadystatechange = HandleNotifiaction(cat);
And changed "Handlenotification" to this:

Code:
function HandleNotifiaction(Span) 
	{	
		if (http.readyState == 1)
		{ 
			document.getElementById(Span).innerHTML = "Please wait, loading..." ; 
		} 
		else if (http.readyState == 4 && http.status == 200)
		{
			var response = http.responseText;
			
			document.getElementById(Span).innerHTML = response;
		}
	}
But it only works for the first "innerHTML". It keeps saying "Please wait, loading...". Though, the data will be submitted correctly. Seems like "cat" gets lost somewhere.

I have 2 spans and want to update the correct one, without creating 2 functions.

Help is appreciated as always.
Reply With Quote
  #2 (permalink)  
Old 03-30-06, 06:54 PM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
I don't think it's possible to send an argument with a direct call, instead let's take a small round trip:
Code:
http.onreadystatechange =function() { 
       HandleNotification(http, cat);
}

...

function HandleNotification(http,Span){
...
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.

Last edited by TwoD; 03-30-06 at 06:55 PM. Reason: Schpellling waz wong..
Reply With Quote
  #3 (permalink)  
Old 03-31-06, 02:20 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Thanks a lot, Sir! Works perfectly!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pushing data to clients brokennb PHP 2 06-16-05 08:52 PM
Passing text vs numeric data as ID from one ASP page to another arobbo61 ASP 7 09-24-04 01:02 AM
Array passing between functions alfreds PHP 1 08-25-03 05:29 AM


All times are GMT -5. The time now is 11:05 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.