When I try to read my cookie that I have set something does not seem right
Here is my cookie functions
function readCookie(){
if (document.cookie !=""){
document.getElementsByName("eMail").innerHTML = alert("hello, " +
document.cookie.split("=")[1]);
}
}
//for setting cookies
function writeCookie(cName, cValue, expDate, cPath, cDomain, cSecure){
if(cName && cValue!= ""){
var cString = cName + " = " + escape(cValue);
if (expDate) cString += ";expires=" + expDate,toGMString();
if (cPath) cString += ";path=" + cPath;
if (cDomain) cString += ";domain=" + cDomain;
if (cSecure) cString += ";secure";
document.cookie = cString;
}
}
cookie being set
<input type="submit" value="Submit"
onclick="writeCookie('userId',document.getElementsByName('eMail').value)"/>
alert box
hello, undefined;__utma
thought on what this means?
The alert function returns
undefinedSo
Is setting the html of
eMailtoundefined.Also,
getElementsByNamereturns a collection of elements.Did you mean
Or are there multiple elements with this name?
Finally, if there’s only one element you’re targeting, you can give it a (unique) id, then simply do