Hi I have made a program in which we have to read cookies through javascript but I am facing a problem in it. And I am unable to understand where the problem is? Please help me understand the same.

<html>
<head>
<title>read cookies</title>

<script language="javascript">
function gettime(){
if(document.cookie)
{
index=document.cookie.indexOf(cookie_name);
if(index!=-1)
countbegin=(documnet.cookie.indexOf("=",index);
countend=document.cookie.indexOf(";",index);
if(countend == -1)
countend=document.cookie.length;
}
count=document.cookie.substring(countbegin,countend);
if(count==1)
return(count+"time");
}
else
{
return(count+ "times");
}
}}
return("0 times");
}
</script>
</head>
</html>

Recommended Answers

All 7 Replies

Java and JavaScript are not the same. Post moved to JavaScript section

ok but wheres the answer for my question?

Hi I have made a program in which we have to read cookies through javascript but I am facing a problem in it. And I am unable to understand where the problem is? Please help me understand the same.

<html>
<head>
<title>read cookies</title>

<script language="javascript">
function gettime(){
if(document.cookie)
{
index=document.cookie.indexOf(cookie_name);
if(index!=-1)
countbegin=(documnet.cookie.indexOf("=",index);
countend=document.cookie.indexOf(";",index);
if(countend == -1)
countend=document.cookie.length;
}
count=document.cookie.substring(countbegin,countend);
if(count==1)
return(count+"time");
}
else
{
return(count+ "times");
}
}}
return("0 times");
}
</script>
</head>
</html>

You did not used the braces properly in the javascript function.
Use the proper indentation, it will help to debug the code.
Starting braces '{' are 3 and the ending braces '}' are 6 :)

I agree to you but when i showed this code to my senior he said that substring (line 16)should not come there its wrong noe tell me what should i do? and i am unable to find answer through google as well

commented: Read what network18 has mentioned. If you can't understand what he is saying, ask your senior. -1

just clear those braces and post your code again, what you using in the script

<html>
<head>
<title>read cookies</title>

<script language="javascript">
function gettime()
{
if(document.cookie)
{
index=document.cookie.indexOf(cookie_name);
if(index!=-1)
{
countbegin=(document.cookie.indexOf("=",index);
countend=document.cookie.indexOf(";",index);
if(countend == -1)
countend=document.cookie.length;
}
count=document.cookie(countbegin,countend);
if(count==1)
return(count+"time");
}
else
{
return(count+ "times");
}

return("0 times");
}
</script>
</head>
</html>

No error with your code, is it working as you expect it to be.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.