Jump to content

error checking in javascript


Bojak

Recommended Posts

<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! 

Link to comment
https://forums.phpfreaks.com/topic/285380-error-checking-in-javascript/
Share on other sites

<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. 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.