PDA

View Full Version : Page Counter?!?


SpongeBobby
08-18-2002, 02:55 AM
Can someone tell me what i am missing here, it dont seem to work for me. I am completely new to Java..so if i miss something stupid...you'll know.


<SCRIPT LANGUAGE="JavaScript">
*/
document.write("<FORM><INPUT TYPE=HIDDEN NAME='saved' value='1'></FORM>")
function welcome()
{
if(document.cookie == "")
{
var counting = "1";
var when = new Date()
document.cookie = "counting=; expires=" + when.toGMTString();
when.setMonth(when.getMonth() + 1)
var counting = document.forms[0].saved.value;
document.cookie = "counting="+counting+" `; expires=" + when.toGMTString()
document.write("Welcome to my homepage.");
}
else
{
var get = document.cookie;
get = get.substring((get.indexOf("=")+1),get.length);
var count = get.split(" ");
count[0]++
document.write("Thanks for coming back! You have been here "+count[0]+" times.");
document.forms[0].saved.value=count[0];
saveit()
}
}


function saveit()
{
var when = new Date()
document.cookie = "counting=; expires=" + when.toGMTString();
when.setMonth(when.getMonth() + 1)
var counting = document.forms[0].saved.value;
document.cookie = "counting="+counting+"; expires=" + when.toGMTString()
}
welcome()

</SCRIPT>


Thanks,

whammy
08-18-2002, 03:34 AM
I'm a little too tired to go through all the code... but I noticed one thing:

if(document.cookie == "")

should be

if(!document.cookie)

Hope that helps!

SpongeBobby
08-18-2002, 04:13 AM
nope still dont work...the **** with it.. I dont have the patience with something that is suppose to come ready to use, and it dont work..


Thanks anyways

scroots
08-18-2002, 09:27 AM
on your PC do you have cookies enabled?

scroots

SpongeBobby
08-18-2002, 10:22 AM
yes they are

um...
08-18-2002, 04:38 PM
this is what you need:



<SCRIPT LANGUAGE="JavaScript">
document.write("<FORM><INPUT TYPE=HIDDEN NAME='saved' value='1'></FORM>")
function welcome()
{
if(!document.cookie)
{
var counting = "1";
var when = new Date()
document.cookie = "counting=; expires=" + when.toGMTString();
when.setMonth(when.getMonth() + 1)
var counting = document.forms[0].saved.value;
document.cookie = "counting="+counting+" `; expires=" + when.toGMTString()
document.write("Welcome to my homepage.");
}
else
{
var get = document.cookie;
get = get.substring((get.indexOf("=")+1),get.length);
var count = get.split(" ");
count[0]++
document.write("Thanks for coming back! You have been here "+count[0]+" times.");
document.forms[0].saved.value=count[0];
saveit()
}
}


function saveit()
{
var when = new Date()
document.cookie = "counting=; expires=" + when.toGMTString();
when.setMonth(when.getMonth() + 1)
var counting = document.forms[0].saved.value;
document.cookie = "counting="+counting+"; expires=" + when.toGMTString()
}
welcome()

</SCRIPT>


Ive tested this script out on my computer and it works fine for me...hope this helps...
:thumbsup:

um...
08-18-2002, 04:49 PM
(if your wondering what i did differently: I got rid of the */ bit near the beginning as it was giving out a "Syntax Error" message, and incorporated what whammy said...)