Bojak Posted January 15, 2014 Share Posted January 15, 2014 <HTML> <head> <title>Last Visit Cookie Tester</title> <script type='text/javascript'> function myFunction() { var currentDate = new Date(); var dateTime = (currentDate.getMonth()+1) + "/" + currentDate.getDate() + "/" + currentDate.getFullYear(); document.write("Current Date: " + dateTime); document.write("<br>"); document.write("<br>"); document.write("<br>"); document.cookie = dateTime; var lastVisit = document.cookie; document.write("Last Visit: " + lastVisit); } if (dateTime !=="") { document.write("window.dateTime"); alert("Passed! you are awesome!"); else { alert("failed. try again!"); } } </script> </head> <body> <div id="showDate" style="display:none; " > <script type="text/javascript"> myFunction(); </script> </div> <div style="position:absolute; top:20px; left:20px;"> <a href="#" onclick="document.getElementById('showDate').style.display = 'block';"> Show Date </a> </div> </body> </HTML> my if statement isnt working properly. i want to parse the information if the cookie isnt null. guidiance would help so much! Quote Link to comment https://forums.phpfreaks.com/topic/285380-error-checking-in-javascript/ Share on other sites More sharing options...
requinix Posted January 15, 2014 Share Posted January 15, 2014 You're not using document.cookie correctly. document.cookie Quote Link to comment https://forums.phpfreaks.com/topic/285380-error-checking-in-javascript/#findComment-1465312 Share on other sites More sharing options...
Bojak Posted January 16, 2014 Author Share Posted January 16, 2014 <HTML> <head> <title>Last Visit Cookie Tester</title> <script type='text/javascript'> function myFunction() { var currentDate = new Date(); var dateTime = (currentDate.getMonth()+1) + "/" + currentDate.getDate() + "/" + currentDate.getFullYear(); document.write("Current Date: " + dateTime); document.write("<br>"); document.write("<br>"); document.write("<br>"); document.cookie = dateTime; var lastVisit = document.cookie; document.write("Last Visit: " + lastVisit); } if (dateTime !="") { document.cookie = dateTime; // document.write("window.dateTime"); alert("Passed! you are awesome!"); } else { alert("failed. try again!"); } </script> </head> its suppose to post passed in an alert if it not null. im using the alert box as a way to test it. it doesnt seem to help. Quote Link to comment https://forums.phpfreaks.com/topic/285380-error-checking-in-javascript/#findComment-1465365 Share on other sites More sharing options...
requinix Posted January 16, 2014 Share Posted January 16, 2014 You're not using document.cookie correctly. document.cookie Quote Link to comment https://forums.phpfreaks.com/topic/285380-error-checking-in-javascript/#findComment-1465368 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.