Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I pass an element as a parameter?

Status
Not open for further replies.

jroehl

Programmer
Aug 20, 2007
1
US
On the last line of this code an element DIV1 is being evaluated by getElementById(). How can I pass this as a variable parameter?

Statechanged() errors if you try to pass a parameter with it.

Thanks
Jeff Roehl

Code:
var xmlHttp

function showCustomer(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="[URL unfurl="true"]http://onionsalad.com/search.fwx";[/URL]
url=url+"?"+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("DIV1").innerHTML=xmlHttp.responseText;
}
}
 
[1]
[tt]function stateChanged[blue]2[/blue]([blue]sid[/blue])
{
if (xmlHttp.readyState==4)
{
document.getElementById([blue]sid[/blue]).innerHTML=xmlHttp.responseText;
}
}
[/tt]
[2] Replace this line with the following.
>xmlHttp.onreadystatechange=stateChanged;
[tt]
var sdivid="DIV1";
//either constructions
xmlHttp.onreadystatechange=Function("","stateChanged2('"+sdivid+"')");
//or
//xmlHttp.onreadystatechange=function() {stateChanged2(sdivid);};
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top