Test cookies in folder Test site on MyComputer?

HAVE CLIENT-SIDE FORM COOKIE GET AND SET FUNCTIONS IN THE SECOND WINDOW DOCUMENT EXTERNAL JS.FILE OF A DUMY TEST SITE FOLDER ON MYCOMPUTER. IE8 THROWS ‘SYNTAX ERROR’ ON THE ‘WINDOW.LOAD=FUNCTION, FIRST COOKIE FUNCTION HIGHLIGHTED’. CAN I ACTUALLY TEST COOKIES ON A TEST SITE ON MY COMPUTER WITHOUT THE SERVER (MYCOMPUTER) OR A DOMAIN NAME? YEAH NO HECKLING FROM THE PEANUT GALLERY.:nono:

THIS IS THE ONLOAD FUNCTION I’M USING. ANY HELP WOULD BE GREATLY APPRECIATED.



// global variables.
domain = 'file:///C:/Documents%20and%20Settings/new%20user/My%20Documents/mexicali/checkout.html';
path = '/mexicali/';
secure = 0;
 
// function to retrieve a field.

function getC(obj) {
var cookie = '', realvalue = '';
cookie = document.cookie;
var objType = new String(obj.type);
if (obj.name)
var objName = new String(obj.name);
else
var objName = new String(obj[0].name);
var cstart = cookie.indexOf(objName + '=[');
if (cstart == -1) return 1;
var cstartlength = objName.length + 2;
cstart = cstart + cstartlength;
var cend = cookie.indexOf(']', cstart);
realvalue = cookie.substring(cstart, cend);
switch(objType.toLowerCase()) {
case "checkbox" :
if(realvalue == '1') obj.checked = 1;
else obj.checked = 0;
break;
case "undefined" :
obj[realvalue].checked = 1;
break;
case "select-one" :
obj.selectedIndex = realvalue;
break;
case "select-multiple" :
for (var i = 0; i < obj.options.length; i++) {
if ((realvalue.indexOf('+' + i)) > -1)
obj.options[i].selected = 1; 
else
obj.options[i].selected = 0;
}
break;
default :
obj.value = realvalue;
break;
} 
return 1;
}
 
window.onload= getC(this.countryname);
getC(this.firstname);//ERROR 'NOT IMPLIMENTED' THROWN.
getC(this.lastname);
getC(this.company);
getC(this.address);
getC(this.address);
getC(this.city);
getC(this.statename);
getC(this.postalcode);
getC(this.phone);
 
//END OF JS 


Are you running a local web server, or just trying to open the HTML file directly in the browser?

Cookies are a property of HTTP requests and responses, so they don’t exist without a live web server.

Please turn off your CAPS lock key if you reply, it’s very hard to read :slight_smile:

window.onload=getC(this.countryname);

Called like this, getC is called immediately.

this.countryname is undefined,
unless you have a global variable named countryname.

Cookies can be written to and read from the file system,
unless the browser preferences forbid it.

To test, open a page with this script in the head:

window.onload=function(){
   if(document.cookie.toString())alert(document.cookie);
   else document.cookie='cookie=I am a Cookie';

}

Open the page, then refresh it.
If a cookie was saved the first time, it will be read the second time the page opens.

If they are ‘turned off’, an error will be thrown when you call toString().

Hey Guys,
thanks for the responce. I found the cookies all loaded in the web page they where written from ‘checkout.html’ in the web tools of IE8. They where set to expire in a year and do change when I use ‘Ochange=setc()’.
mrhoo thanks for the script.
Will try it.
Dan hey it writes the cookies so it must be able to read them. I’ll try mrhoos skript and get back.

Yeah mrhoo the alert reads them all. Thanks for that. I now need to figure out why getC() isn’t being implimented?

Wierd Science
The countryname input contains the cookie value which happens to be the one calling the ‘ERROR: NOT IMPLIMENTED’ but all the other inputs are empty?:sick:

setC() isn’t reseting the cookies onchange()

Deffinatley need help. This is how I set the onchange for each input.



addEvent(shiptoocountry,'change',function(){
tshipcountry.innerHTML = shiptoocountry.value;
setC(this.shiptoocountry);},false);


:o

rnd me From WebDeveloper.Com thanks for the tip on IIS, I actually removed the IIS compnent from the ‘add/remove programs’ the files for IIS remain on the system but iis.exec isn’t available to access the UI console. Yeah I remain THEFOOL! Other draw back is that Microsoft keeps alerting that the Windows XP isn’t a Microsoft Version. The Computer was bought with the XP Pro already on it and did not come with a DISC! If it had I could have reinstalled. Currently you can download Microsoft SQL Server from Microsoft.com but you can’t download IIS Server.
Back to the Subject of this Thread.
AirShow From DaniWeb thanks, I quessed that if you can write them you can read them and manipulate them etc. I’m amazed at the amount of people that believe they need a server responce to do it.
None the less, javascript may be a loosley typed language but ‘syntax’ is everything! I should have caught that
[B]getC/B; Is suposed to retrieve the cookie value and restore the field value. should work on all fields. Haven’t done it yet but I’m sure you’re right.:slight_smile:
Will post this to WebDeeloper.Com and SitePoint.
Thanks again AirShow for the Enlightment.