Jump to content

Easy fix?? Hopefully.


PICS

Recommended Posts

Hey guys

 

I'm creating a page that utilizes a cookie to set the town.

 

Now my cookie is set fine. The problem occurs when I pull down the cookie and try to pull the correct page with AJAX. The code is below:

 

Cookie Retrieval

 

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

function checkCookie()
{
serverPage= getCookie('cp_town');
serverPage = "/section/fptest?kword=" + serverPage;
if (serverPage!=null && serverPage!="")
{
        var obj = document.getElementById('townbox');
        xmlhttp.open("GET", serverPage);
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                obj.innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.send(null);

	oldserverpage = serverPage;

	serverPage = serverPage.replace("/section/fptest?kword=", "");
	document.getElementById('mytown').innerHTML = "<h3>" + serverPage.replace(/_/i, " ") + "</h3>";
}
}

checkCookie();

 

Any idea why it keeps giving me an error about the document.getElementById('mytown') portion? It tells me it's null.

Link to comment
https://forums.phpfreaks.com/topic/139045-easy-fix-hopefully/
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.