943,942 Members | Top Members by Rank

Ad:
Nov 11th, 2009
-2

Cookies with javascript

Expand Post »
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.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <title>read cookies</title>
  4.  
  5. <script language="javascript">
  6. function gettime(){
  7. if(document.cookie)
  8. {
  9. index=document.cookie.indexOf(cookie_name);
  10. if(index!=-1)
  11. countbegin=(documnet.cookie.indexOf("=",index);
  12. countend=document.cookie.indexOf(";",index);
  13. if(countend == -1)
  14. countend=document.cookie.length;
  15. }
  16. count=document.cookie.substring(countbegin,countend);
  17. if(count==1)
  18. return(count+"time");
  19. }
  20. else
  21. {
  22. return(count+ "times");
  23. }
  24. }}
  25. return("0 times");
  26. }
  27. </script>
  28. </head>
  29. </html>
Similar Threads
Reputation Points: 9
Solved Threads: 0
Newbie Poster
namratakakkar84 is offline Offline
5 posts
since Aug 2009
Nov 11th, 2009
-1
Re: Cookies with javascript
Java and JavaScript are not the same. Post moved to JavaScript section
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 873
Code tags enforcer
peter_budo is offline Offline
6,656 posts
since Dec 2004
Nov 11th, 2009
-1
Re: Cookies with javascript
ok but wheres the answer for my question?
Last edited by namratakakkar84; Nov 11th, 2009 at 5:59 am.
Reputation Points: 9
Solved Threads: 0
Newbie Poster
namratakakkar84 is offline Offline
5 posts
since Aug 2009
Nov 12th, 2009
0
Re: Cookies with javascript
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.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <title>read cookies</title>
  4.  
  5. <script language="javascript">
  6. function gettime(){
  7. if(document.cookie)
  8. {
  9. index=document.cookie.indexOf(cookie_name);
  10. if(index!=-1)
  11. countbegin=(documnet.cookie.indexOf("=",index);
  12. countend=document.cookie.indexOf(";",index);
  13. if(countend == -1)
  14. countend=document.cookie.length;
  15. }
  16. count=document.cookie.substring(countbegin,countend);
  17. if(count==1)
  18. return(count+"time");
  19. }
  20. else
  21. {
  22. return(count+ "times");
  23. }
  24. }}
  25. return("0 times");
  26. }
  27. </script>
  28. </head>
  29. </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
Last edited by network18; Nov 12th, 2009 at 4:24 am.
Reputation Points: 29
Solved Threads: 76
Practically a Master Poster
network18 is offline Offline
616 posts
since Sep 2009
Nov 12th, 2009
-1
Re: Cookies with javascript
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
Reputation Points: 9
Solved Threads: 0
Newbie Poster
namratakakkar84 is offline Offline
5 posts
since Aug 2009
Nov 12th, 2009
0
Re: Cookies with javascript
just clear those braces and post your code again, what you using in the script
Reputation Points: 29
Solved Threads: 76
Practically a Master Poster
network18 is offline Offline
616 posts
since Sep 2009
Nov 12th, 2009
0
Re: Cookies with javascript
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <title>read cookies</title>
  4.  
  5. <script language="javascript">
  6. function gettime()
  7. {
  8. if(document.cookie)
  9. {
  10. index=document.cookie.indexOf(cookie_name);
  11. if(index!=-1)
  12. {
  13. countbegin=(document.cookie.indexOf("=",index);
  14. countend=document.cookie.indexOf(";",index);
  15. if(countend == -1)
  16. countend=document.cookie.length;
  17. }
  18. count=document.cookie(countbegin,countend);
  19. if(count==1)
  20. return(count+"time");
  21. }
  22. else
  23. {
  24. return(count+ "times");
  25. }
  26.  
  27. return("0 times");
  28. }
  29. </script>
  30. </head>
  31. </html>
Last edited by namratakakkar84; Nov 12th, 2009 at 7:26 am.
Reputation Points: 9
Solved Threads: 0
Newbie Poster
namratakakkar84 is offline Offline
5 posts
since Aug 2009
Nov 12th, 2009
0
Re: Cookies with javascript
No error with your code, is it working as you expect it to be.
Reputation Points: 29
Solved Threads: 76
Practically a Master Poster
network18 is offline Offline
616 posts
since Sep 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: onmouseover not working in ie
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Dynamic table rows





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC