Q: getCookie IE issue For the life of me I can't figure out why the following getcookie code won't work in IE. It is exactly what I want to happen, and works fine on all other browsers (FireFox, Safari, Chrome, Etc.).
I keep getting 'document.getElementByID(...)childNodes.0' is null or not an object...
Please advise.
Thanks,
JG
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Example using cookie</title>

<script type="text/javascript">
// function to set the cookie
function SetCookie () {
// variabiles that gets the form values
  var ssqname = document.prefers.ssqname.value;

  // Set the expiration time, 2 days
  var twoDays = 2*24*60*60*1000
  var expDate = new Date()
  expDate.setTime(expDate.getTime()+twoDays);

  // Create the cookies
  document.cookie = "cookie1" + "=" + escape(ssqname) + "; expires=" + expDate.toGMTString() ;
}

// This function checks if exist the cookie with the name passed in the argument
// If that cookie exists gets and return its value
  function checkCookie(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));
    }
  }
  // If the cookie not exists
  return "You have not yet added a preference";
}

// This function gets the cookie values from the checkCookie() and stores them in an array
// Dysplays it the page the cookie values
function getCookie() {
  nr = getCookie.arguments.length

  var val_c = new Array(nr)
  var a = 0

  for (var i=0; i<nr; i++) {
    valoare=checkCookie(getCookie.arguments[i]);
    if (valoare!=null && valoare!="") {
    val_c[a] = valoare;
    a++
    }
  }

  // Dysplays the cookie values, at the indicated id
  document.getElementById("showname").childNodes[0].nodeValue = val_c[0];
}

// This function deletes the cookies
function delCookies() {
  nr_c = delCookies.arguments.length
  var ThreeDays = 3*24*60*60*1000;
  var expDate = new Date();
  expDate.setTime (expDate.getTime() - ThreeDays);

   for (var n=0; n<nr; n++) {
document.cookie = delCookies.arguments[n] + "=DataDel; expires=" + expDate.toGMTString();
  }
}
</script>
</head>
<body>
<table border="1" bordercolor="#8888fe" width="580" cellpadding="2" cellspacing="0">
  <tr><td>
  <form name="prefers">
        Your Name:
        <input type="text" name="ssqname" size="20" maxlength="40" /><br /><br />
        <input type="button" value="Start" name="buton" onclick="SetCookie()" />
      </form>
      </td><td>
      <form name="prefers2">
        <input type="button" value="Show Name" name="buton" onclick="getCookie('cookie1')" />&nbsp;
        <input type="button" value="Delete cookie" name="Clear" onclick="delCookies('cookie1')" />
      </form>
      <body onLoad="getCookie('cookie1')">
  <b>Your Name - </b><span id="showname"> </span><br />
  </td></tr>
</table>
</body>
</html>


A: IE ignores textNodes when they contain only whiteSpaces, so IE will not find any childNodes inside the element.
You may use this:
try{document.getElementById("showname").childNodes[0].nodeValue = val_c[0];}
catch(e){document.getElementById("showname").appendChild(document.createTextNode(val_c[0]));}

