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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.