tags:

views:

21

answers:

1

Hi, I am using a Datepicker on my site and want the current day (selected on page load) to advance one day forward at 2pm.

$(function() {
var dd = 0
var dsc = new Date();
if (dsc.getHours() > 14) {
dd = dd + 1; // go one day in the future
}

Works perfectly but this uses the local time on the users machine.

So I tried this.

$(function() {       
var dd = 0
var dsc = ('<%= currentHour %>');
if (dsc > 14) {
dd = dd + 1; // go one day in the future
}

The currentHour gets it's value from

Dim currentHour
currentHour = Hour(Now)

But this won't work. Can anyone help.

A: 

I am assuming you are declaring currentHour on the server side and that it outputs correctly in the JavaScript fragment you posted.

You don't need to put the currentHour in quotes and parentheses.

$(function() {       
  var dd = 0
  var dsc = <%= currentHour %>;
  if (dsc > 14) {
    dd = dd + 1; // go one day in the future
  }
}

You don't need the dsc variable either:

$(function() {       
  var dd = 0
  if (<%= currentHour %> > 14) {
    dd = dd + 1; // go one day in the future
  }
}

Edit: (following the comments)

The <%= %> syntax is an asp feature that will only be processed when in an ASP page. If this is in a static JS file, it will remain as it is and not be processed.

Oded
Thanks Oded, tried your code and it crashed the calendar, changed (<%= currentHour %> > 14) to ('<%= currentHour %>' > 14) and calendar back, but still won't add a day on.
Darren Cook
Where is `currentHour` created? In client side or server side VBScript?
Oded
Server side VBScript.
Darren Cook
And the JS file is on the same page or in a JS file?
Oded
Yes, it's a file include.
Darren Cook
An asp include or a JS file?
Oded
It is a JS include.
Darren Cook
That's your problem. The JS file will not be processed by the asp engine, so <%= %> never get processed. You need that JS inline on the page, on in an asp include.
Oded
That's fixed it, moved the JS inline and it works a dream. Thanks Oded.BTW, I did still need to leave the '<%=%>' for it to display correctly.
Darren Cook
Shouldn't need to. Strange.
Oded