I took the javascript snippet below out of a larger script. The larger script works. The snippet below does not.
That means firebug tells me:
1) It does not post a name/value pair to its php script.
2) Placing its variables in the alert function does not bring an alert box to the browser screen.
Everything else in the larger script this snippet came from works. The larger script has html tags I did not copy into the snippet below (I did copy the <body> tag).
The "crystal" ajax object works, as shown by an alert box. Nothing else in this script does.
I know I don't have anything in the onreadystatechange function, but I don't think that should stop an alert box from showing the contents of a variable or the send method from posting the name/value pair.
I tested this by writing it to run onload. It does'nt run when the browser is refreshed.
What am I missing?
Thanks
The code:
Code:
<body>
<script type="text/javascript">
var Sally = new Date();
var month = Sally.getMonth(); //returns the month (0-11)
if(month==0)
{
month = "Jan";
}
if(month==1)
{
month = "Feb";
}
if(month==2)
{
month = "Mar";
}
if(month==3)
{
month = "Apr";
}
if(month==4)
{
month = "May";
}
if(month==5)
{
month = "Jun";
}
if(month==6)
{
month = "Jul";
}
if(month==7)
{
month = "Aug";
}
if(month==8)
{
month = "Sep";
}
if(month==9)
{
month = "Oct";
}
if(month==10)
{
month = "Nov";
}
if(month==11)
{
month = "Dec";
}
var day = Sally.getDate(); //returns day of month (1-31)
var year = Sally.getFullYear(); //returns year (xxxx)
var hour = Sally.getHours(); //returns hours (0-23)
if(hour = 0){hour = 12AM}
if(hour = 1){hour = 1AM}
if(hour = 2){hour = 2AM}
if(hour = 3){hour = 3AM}
if(hour = 4){hour = 4AM}
if(hour = 5){hour = 5AM}
if(hour = 6){hour = 6AM}
if(hour = 6){hour = 6AM}
if(hour = 7){hour = 7AM}
if(hour = 8){hour = 8AM}
if(hour = 8){hour = 8AM}
if(hour = 9){hour = 9AM}
if(hour = 10){hour = 10AM}
if(hour = 11){hour = 11AM}
if(hour = 12){hour = 12PM}
if(hour = 13){hour = 1PM}
if(hour = 14){hour = 2PM}
if(hour = 15){hour = 3PM}
if(hour = 16){hour = 4PM}
if(hour = 17){hour = 5PM}
if(hour = 18){hour = 6PM}
if(hour = 19){hour = 7PM}
if(hour = 20){hour = 8PM}
if(hour = 21){hour = 9PM}
if(hour = 22){hour = 10PM}
if(hour = 23){hour = 11PM}
var dateTime = month+day+year+hour;
var parameters = "dateTime="+dateTime
crystal.open("POST", "/cgi-bin/check_current_dateTime_to_see_if_this_apt_time_is_now_so_display_none.php", false);
crystal.onreadystatechange = function()
{
if(crystal.readyState == 4)
{
if(crystal.status == 200)
{
}
}
}
crystal.setRequestHeader("Content-type","application/x-www-form-urlencoded");
crystal.send(parameters);
</script>
</body>
UPDATE:
The mistake I was making was with the hour if statements. I wrote this on every line:
Code:
if(hour = 0){hour = 12AM}
I corrected it by writing this on every line:
Code:
if(hour == 0){hour = '12AM'}