Pinecone Tortoise
'Piney'
Yo! First time writing javascript, though I've had a bit of experience with other languages. This function is mostly taken from code I've found on some of the tutorial sites, so it presumably works. It appeared to work when I tested it on the site I'm building but when further changes were made to the css and so forth, a nasty bunch of other strange things started happening.
I'm thinking it'd be a lot easier to fix the other problems if I actually UNDERSTOOD what this function was doing. The comments that came with it were rather non-explicit and perhaps intended for someone actually familiar with the javascript syntax. @_@ Help anyone?
function get_Cookie(name) {
var search =name + "="
var returnvalue ="";
if (document.cookie.length > 0) {
firsty = document.cookie.indexOf(search)
if (firsty!= -1) {
firsty+= search.length
lasty = document.cookie.indexOf(";", firsty);
if (lasty == -1)
lasty = document.cookie.length;
returnvalue=unescape(document.cookie.substring(firsty,lasty))
}
}
return returnvalue;
}
Now, I'm guessing that what it's actually DOING is to take the position in the cookie string of the start of the 'value' part and the position of the end of the value part and outputting the substring between them. But I'm just guessing here.
And what on earth does the '+=' mean in the line 'firsty+= search.length'? And is search a regular variable or one of those special words that javascript already knows about? (Please pardon the terminology slip there... can't remember what those things are called. Exception words? Bah, it doesn't matter anyway. You lot know what I'm talking about, right?)
Anyway, a step through of what this little beauty is doing would really help. Thanks!
Piney.
;204;;324;
I'm thinking it'd be a lot easier to fix the other problems if I actually UNDERSTOOD what this function was doing. The comments that came with it were rather non-explicit and perhaps intended for someone actually familiar with the javascript syntax. @_@ Help anyone?
function get_Cookie(name) {
var search =name + "="
var returnvalue ="";
if (document.cookie.length > 0) {
firsty = document.cookie.indexOf(search)
if (firsty!= -1) {
firsty+= search.length
lasty = document.cookie.indexOf(";", firsty);
if (lasty == -1)
lasty = document.cookie.length;
returnvalue=unescape(document.cookie.substring(firsty,lasty))
}
}
return returnvalue;
}
Now, I'm guessing that what it's actually DOING is to take the position in the cookie string of the start of the 'value' part and the position of the end of the value part and outputting the substring between them. But I'm just guessing here.
And what on earth does the '+=' mean in the line 'firsty+= search.length'? And is search a regular variable or one of those special words that javascript already knows about? (Please pardon the terminology slip there... can't remember what those things are called. Exception words? Bah, it doesn't matter anyway. You lot know what I'm talking about, right?)
Anyway, a step through of what this little beauty is doing would really help. Thanks!
Piney.
;204;;324;