i am not a javasript programmer by any stretch but
i have been writing a javascript programmer for
a friend that does the following :
1) prompts the user for first name, middle name and last name
2) saves the data in a cookie
3) spits the cookie data back out to the respective fields
i think it's very close to working but
i am getting an error. i don't have a javascript debugger
(nor would i know how to use one if i did have it because
this is my first javascript program )
so i am pretty stuck and i found this website.
i would really appreciate it if someone could look at it
and let me know if they see the problem ?
if you are reasonably decent at javascript,
it probably wouldn't take very long. i'm not
so familar with this language.
thanks a lot.
the code is below.
----------------------------------------------------------------------
<html>
<head><title> A Cookie Example </title>
<script language="JavaS cript">
function getCookieVal(na me,index) {
name = name + "=";
var ck = document.cookie ;
document.write( document.cookie )
if ( ck.length > 0) {
firstcharpos = ck.indexOf(name );
if ( firstcharpos != -1){
endrecord = ck.indexOf(";", firstcharpos+na me.length);
if(endrecord == -1) {
endrecord = ck.length;
}
var lastindexpos = firstcharpos + name.length;
// scan for separator bars
for (i=0; i<index;i++) {
if (i!=0){lastinde xpos++}
firstindexpos = lastindexpos;
lastindexpos = ck.indexOf("|", firstindexpos);
}
// if we can't find another bar then go to the end of the record
if ( lastindexpos == -1) {
lastindexpos = endrecord;
}
document.write( " " + "<br>")
// scan last entry for semi colons. we may find a bar but it could
belong to the next entry
document.write( "first index position is " + firstindexpos + " last is
" + lastindexpos + "<br>");
substring = ck.substring(fi rstindexpos,las tindexpos);
sc = substring.index Of(";");
if (sc==-1){
return(unescape (ck.substring(f irstindexpos,la stindexpos)));
} else {
return(unescape (ck.substring(f irstindexpos,en drecord)));
}
}
}
return null;
}
function setCookie(name, form) {
var combined_string = form.fnameCooki e.value + "|" +
form.mnameCooki e.value + "|" + form.lnameCooki e.value;
document.cookie = "name=" + combined_string + ";";
document.write( combined_string )
document.write( document.cookie )
form.fnameCooki e.value="";
form.mnameCooki e.value="";
form.lnameCooki e.value="";
document.write( document.cookie )
}
function showCookie(form ) {
form.fnameCooki e.value=getCook ieVal("Cookie", 1)
document.write( form.fnameCooki e.value)
form.mnameCooki e.value=getCook ieVal("Cookie", 2)
form.lnameCooki e.value=getCook ieVal("Cookie", 3)
}
</script>
</head>
<body bgcolor="#CCFFF F"><center>
<h2>A Cookie Example</h2>
<form>
<p>Please enter text to set the first name<br>
<input type="text" name="fnameCook ie" value="" size=50>
<p>Please enter text to set the middle name<br>
<input type="text" name="mnameCook ie" value="" size=50>
<p>Please enter text to set the last name<br>
<input type="text" name="lnameCook ie" value="" size=50>
<p>Click on this button to save the cookie <br><br>
<input type="button" value="Create Cookie" name="SetButton "
onClick="setCoo kie('Cookie', this.form);">
<p>Now click on this button to show the values in the text boxes
<br><br>
<input type="button" value="Display Cookie" name="DisplayBu tton"
onClick="showCo okie(this.form) ;">
</form>
</center>
</body>
</html>
i have been writing a javascript programmer for
a friend that does the following :
1) prompts the user for first name, middle name and last name
2) saves the data in a cookie
3) spits the cookie data back out to the respective fields
i think it's very close to working but
i am getting an error. i don't have a javascript debugger
(nor would i know how to use one if i did have it because
this is my first javascript program )
so i am pretty stuck and i found this website.
i would really appreciate it if someone could look at it
and let me know if they see the problem ?
if you are reasonably decent at javascript,
it probably wouldn't take very long. i'm not
so familar with this language.
thanks a lot.
the code is below.
----------------------------------------------------------------------
<html>
<head><title> A Cookie Example </title>
<script language="JavaS cript">
function getCookieVal(na me,index) {
name = name + "=";
var ck = document.cookie ;
document.write( document.cookie )
if ( ck.length > 0) {
firstcharpos = ck.indexOf(name );
if ( firstcharpos != -1){
endrecord = ck.indexOf(";", firstcharpos+na me.length);
if(endrecord == -1) {
endrecord = ck.length;
}
var lastindexpos = firstcharpos + name.length;
// scan for separator bars
for (i=0; i<index;i++) {
if (i!=0){lastinde xpos++}
firstindexpos = lastindexpos;
lastindexpos = ck.indexOf("|", firstindexpos);
}
// if we can't find another bar then go to the end of the record
if ( lastindexpos == -1) {
lastindexpos = endrecord;
}
document.write( " " + "<br>")
// scan last entry for semi colons. we may find a bar but it could
belong to the next entry
document.write( "first index position is " + firstindexpos + " last is
" + lastindexpos + "<br>");
substring = ck.substring(fi rstindexpos,las tindexpos);
sc = substring.index Of(";");
if (sc==-1){
return(unescape (ck.substring(f irstindexpos,la stindexpos)));
} else {
return(unescape (ck.substring(f irstindexpos,en drecord)));
}
}
}
return null;
}
function setCookie(name, form) {
var combined_string = form.fnameCooki e.value + "|" +
form.mnameCooki e.value + "|" + form.lnameCooki e.value;
document.cookie = "name=" + combined_string + ";";
document.write( combined_string )
document.write( document.cookie )
form.fnameCooki e.value="";
form.mnameCooki e.value="";
form.lnameCooki e.value="";
document.write( document.cookie )
}
function showCookie(form ) {
form.fnameCooki e.value=getCook ieVal("Cookie", 1)
document.write( form.fnameCooki e.value)
form.mnameCooki e.value=getCook ieVal("Cookie", 2)
form.lnameCooki e.value=getCook ieVal("Cookie", 3)
}
</script>
</head>
<body bgcolor="#CCFFF F"><center>
<h2>A Cookie Example</h2>
<form>
<p>Please enter text to set the first name<br>
<input type="text" name="fnameCook ie" value="" size=50>
<p>Please enter text to set the middle name<br>
<input type="text" name="mnameCook ie" value="" size=50>
<p>Please enter text to set the last name<br>
<input type="text" name="lnameCook ie" value="" size=50>
<p>Click on this button to save the cookie <br><br>
<input type="button" value="Create Cookie" name="SetButton "
onClick="setCoo kie('Cookie', this.form);">
<p>Now click on this button to show the values in the text boxes
<br><br>
<input type="button" value="Display Cookie" name="DisplayBu tton"
onClick="showCo okie(this.form) ;">
</form>
</center>
</body>
</html>
Comment