Page 1 of 1

Sending element name to javascript function

Posted: Wed Nov 21, 2007 11:59 pm
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

Posted: Thu Nov 22, 2007 1:45 am
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.