Cookies with javascript

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Aug 2009
Posts: 5
Reputation: namratakakkar84 is an unknown quantity at this point 
Solved Threads: 0
namratakakkar84 namratakakkar84 is offline Offline
Newbie Poster

Cookies with javascript

 
-2
  #1
34 Days Ago
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>
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,240
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 490
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is online now Online
Code tags enforcer
 
-1
  #2
34 Days Ago
Java and JavaScript are not the same. Post moved to JavaScript section
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 5
Reputation: namratakakkar84 is an unknown quantity at this point 
Solved Threads: 0
namratakakkar84 namratakakkar84 is offline Offline
Newbie Poster
 
-1
  #3
33 Days Ago
ok but wheres the answer for my question?
Last edited by namratakakkar84; 33 Days Ago at 5:59 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 552
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is online now Online
Posting Pro
 
0
  #4
33 Days Ago
Originally Posted by namratakakkar84 View 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>
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; 33 Days Ago at 4:24 am.
"The discipline of writing something down is the first step towards making it happen."

follow me on twitter
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 5
Reputation: namratakakkar84 is an unknown quantity at this point 
Solved Threads: 0
namratakakkar84 namratakakkar84 is offline Offline
Newbie Poster
 
-1
  #5
33 Days Ago
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 552
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is online now Online
Posting Pro
 
0
  #6
32 Days Ago
just clear those braces and post your code again, what you using in the script
"The discipline of writing something down is the first step towards making it happen."

follow me on twitter
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 5
Reputation: namratakakkar84 is an unknown quantity at this point 
Solved Threads: 0
namratakakkar84 namratakakkar84 is offline Offline
Newbie Poster
 
0
  #7
32 Days Ago
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; 32 Days Ago at 7:26 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 552
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is online now Online
Posting Pro
 
0
  #8
32 Days Ago
No error with your code, is it working as you expect it to be.
"The discipline of writing something down is the first step towards making it happen."

follow me on twitter
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC