Sending element name to javascript function

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
shivam0101
Forum Contributor
Posts: 197
Joined: Sat Jun 09, 2007 12:09 am

Sending element name to javascript function

Post by shivam0101 »

Code: Select all

function Actions(id, process)
{ 
	document.getElementById("nextstepsdiv").className="lodinggif";
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
  	{
  		alert ("Your browser does not support AJAX!");
 		 return;
 	} 

	xmlHttp.onreadystatechange=nextstepChanged;
	xmlHttp.open("GET",'/user_actions.php?id='+id+'&process='+process,true);
	xmlHttp.send(null);
}
In the above code i want to make process in (function Actions(id, process)
) is same as ("nextstepsdiv") in document.getElementById("nextstepsdiv").className="lodinggif";
.

i.e, I want the div element to be called dynamically depending on the value of process

For example,

if i call the function

Code: Select all

Actions(1, div1);,
it should get element id div1
if i call the function

Code: Select all

Actions(1, div2);,
it should get element id div2

i tried,

Code: Select all

function Actions(id, process)
{ 
	document.getElementById(process).className="lodinggif";
I am getting error, document.getElementById is null
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

First things first.

Code: Select all

Actions(1, 'div2');
Need to quote the name(String) so JavaScript doesn't try looking for the variable div2.
Post Reply