alternative way of writing cookies using substring

wxdqz

New Member
hi guys, i have two html pages and what i'm trying to do is to write html2 in a slighty different way. if you look at html2 there is a code like this: NameString = document.cookie.substring(Pos+20,Pos+8) //extract the 12 characters from where the name starts. now this code requires me to look for a file called cookie.txt on netscape subdirectory as you can see from the attachment!! BUT the main problem i got is i cannot find the cookie.txt file in netscape 8.0 folder. so i was wondering if there is an alternative way or easier way of writing the code in html2 without looking at the cookie.txt file.
thanks

here are the two hmtl page:
.............................html1................ ........
<body bgcolor=green vlink=white>


<SCRIPT LANGUAGE=JAVASCRIPT>
//trycookie.htm


function AddTotal () {
document.myForm.Total.value = document.myForm.Item1.checked + document.myForm.Item2.checked
+ document.myForm.Item3.checked + document.myForm.Item4.checked
}

function setCookieUser() {
var expire = new Date()
var oneHour = expire.getTime() + (60 * 60 * 1000)
expire.setTime(oneHour)
userName = document.myForm.nameField.value
document.cookie = "userName="+userName+";expires=" + expire.toGMTString()
}


function displayCookie() {
alert(document.cookie)
}




function setCookie() {
var expire = new Date()

var oneHour = expire.getTime() + (60 * 60 * 1000)
expire.setTime(oneHour)
itemsOrdered = document.myForm.Total.value
document.cookie = "Ordered="+itemsOrdered +"; expires=" +
expire.toGMTString()
}

// deleting refreshes other entries into file
// must match name+value to delete
function deleteIt() { //set the cookie name with an expired date to delete it
document.cookie = "userName=hhh; expires=Thu, 01-Jan-70 00:00:01 GMT"
}



</script>




<FORM NAME=myForm>
Enter your name : <INPUT SIZE =12 TYPE="text" name=nameField onBlur="setCookieUser()">
(will set userName cookie when being typed in)<p>
<INPUT TYPE="button" VALUE=http://www.webdeveloper.com/forum/archive/index.php/"Display Cookies"
onClick="displayCookie()">
<INPUT TYPE="button" VALUE="Delete A Cookie Value"
onClick="deleteIt()">
<P>
Choose your items: <br>
<INPUT TYPE="checkbox" NAME="Item1" VALUE="Item1" onClick="AddTotal()" > <br>
<INPUT TYPE="checkbox" NAME="Item2" VALUE="Item2" onClick="AddTotal()"> <br>
<INPUT TYPE="checkbox" NAME="Item3" VALUE="Item3" onClick="AddTotal()"> <br>
<INPUT TYPE="checkbox" NAME="Item4" VALUE="Item4" onClick="AddTotal()"> <br>
<INPUT TYPE="button" VALUE="Set Ordered cookie"
onClick="setCookie()">
<P>
Total = <INPUT SIZE =12 TYPE="text" name=Total >

</FORM>

...................................

........................html2..................... ...
<HTML>
<BODY>
This is the value of my cookie

<body bgcolor=orange vlink=white>


<SCRIPT LANGUAGE=JAVASCRIPT>
//trycookie2.htm

document.open() //to be able to print to the browser screen
Pos= document.cookie.indexOf("userName") //search for userName in cookie string
NameString = document.cookie.substring(Pos+20,Pos+8) //extract the 12 characters from where the name starts
Pos= document.cookie.indexOf("Ordered")
OrderedString = document.cookie.substring(Pos+10,Pos+8)

document.writeln( "Name "+ NameString + " Ordered= " + OrderedString)
// print out to the browser page
document.close()


</script>
</body>
 
Top