Jump to content

more than one script tags not working


squiblo

Recommended Posts

when i only have this on the page...it works perfectly

 

<script>
var xmlhttp;

function chat1()
{
showUser1();
}

function showUser1(str)
{
xmlhttp=GetXmlHttpObject1();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url1="http://localhost/includes/chat/chat_output/sql_output/sql1.php";
url1=url1+"?q="+str;
url1=url1+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged1;
xmlhttp.open("GET",url1,true);
xmlhttp.send(null);
}

function stateChanged1()
{
if (xmlhttp.readyState==4)
{
document.getElementById("chatoneoutput").innerHTML=xmlhttp.responseText;
showUser1();
}
}

function GetXmlHttpObject1()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}
</script>

<div id="chatoneoutput"><b></b></div>

 

the only problem is that i also want this on the page

 

<script>
var xmlhttp;

function chat2()
{
showUser2();
}

function showUser2(str)
{
xmlhttp=GetXmlHttpObject2();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url2="http://localhost/includes/chat/chat_output/sql_output/sql2.php";
url2=url2+"?q="+str;
url2=url2+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged2;
xmlhttp.open("GET",url2,true);
xmlhttp.send(null);
}

function stateChanged2()
{
if (xmlhttp.readyState==4)
{
document.getElementById("chattwooutput").innerHTML=xmlhttp.responseText;
showUser2();
}
}

function GetXmlHttpObject2()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}
</script>

<div id="chattwooutput"><b></b></div>

 

You will notice they are nearly the same but different. When I add the second one, the 1st one stops working (nothing is shown) but then the 2nd one works perfectly, how can i make them both work properly without them effecting one another.. thanks :)

Link to comment
https://forums.phpfreaks.com/topic/198467-more-than-one-script-tags-not-working/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.