Forum Moderators: open

Message Too Old, No Replies

Passing Javascript Value to ASP Page

Javascript and ASP

         

hazee

10:06 pm on May 21, 2005 (gmt 0)

10+ Year Member



I have a function in javascript which converts the server time according to my local time ... that is GMT +4 ... I need to store this local generated time in Table using ASP. Here is the function.

function showlocaltime() {
var today = new Date();
var difftime = (today.getTimezoneOffset()+240) *60000;
today.setTime(today.getTime()+difftime);
alert(today.toLocaleString());
}
//240=4*60 because my local time is GMT+4

Here is the ASP page .. which stores record in Table ... How can I change the function now() to the generated value of Javascript function?

rstSearch.CursorType = 2
rstSearch.LockType = 3
strSQL= "SELECT * FROM tblMessages"
rstSearch.Open strSQL, adoCon
rstSearch.AddNew
rstSearch.Fields(1)=session("username")
rstSearch.Fields(2)=request.Form("textfield")
rstSearch.Fields(3) =request.Form("textfield2")
rstSearch.Fields(4)=request.Form("textarea")
rstSearch.Fields(5)=now 'NEED TO CHANGE
rstSearch.Fields(6)=false
rstSearch.update
rstSearch.close
response.Redirect("messages.asp?id=4")

Regards,

mattglet

2:06 am on May 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You should probably think about porting that function to VBScript, and using it that way.

The only real efficient way to pass data from JavaScript to ASP is via cookies (set it in JS, read it in ASP).

hazee

5:00 am on May 22, 2005 (gmt 0)

10+ Year Member



ok ..

In short, How can I convert the SERVER TIME into GMT+4 and to display it in ASP page.

any idea?

Regards.

hazee

9:16 am on May 22, 2005 (gmt 0)

10+ Year Member



I found the solution but now stuck with one other thing.

function showlocaltime() {
var today = new Date();
var difftime = (today.getTimezoneOffset()+240) *60000;
today.setTime(today.getTime()+difftime);
document.forms.frmMessagesent.hiddenField.value=today.toLocaleString();}

Above written code returns the date in following format.

Monday, May 23, 2005 12:59:14

Which cannot be stored as a date/time value in MSACCESS and SQL SERVER date/time fields.

Any Idea, how can we convert it (date and time both), USING ASP or it should be done using javascript?

Regards,

gregpakes

10:02 am on May 22, 2005 (gmt 0)

10+ Year Member



can you not just use the 'Now()' keyword?

Rather than using your javascript to return the date and time - you can run 'NOW()' in ASP...

SQL = "Insert into tblTable Values ('value','" & Now() & "');"

mattglet

12:58 pm on May 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



gregpakes-
The whole point of this is to get his GMT offset time, so Now() will not work.

hazee-
Instead of populating your hidden field via JavaScript, you should do it via ASP:

<input type = "hidden" name = "myname" value = "<%=DateAdd("h", 4, Now())%>">

This will add 4 hours onto your server time.

gregpakes

1:56 pm on May 22, 2005 (gmt 0)

10+ Year Member



Mattglet -

I gather that it is for time difference - so just do as you put in your post - namely dateadd... The point I was making was to use the Now() method.

mattglet

2:15 pm on May 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Even so, if you're going to use inline SQL, you should use SQL's GETDATE() function, instead of ASP's Now().

i.e.

SQL = "INSERT INTO yourtable (mydate) VALUES (GETDATE())"

hazee

8:22 pm on May 22, 2005 (gmt 0)

10+ Year Member



Thanks everybody,

Instead of populating your hidden field via JavaScript, you should do it via ASP:  

<input type = "hidden" name = "myname" value = "<%=DateAdd("h", 4, Now())%>">

This will add 4 hours onto your server time.

It was helpful, although I had to calculate the difference between the time of server and our local timings. Anyways ..

Thanks and regards.

campjer

7:35 pm on Jun 14, 2005 (gmt 0)



I finally found a solution for this... Some Whizbang over at Slive Five in Cincinnati wrote some perfect code for it.

The answers to all your problems should be solved here:

[slingfive.com...]

My 36 hours of misery were put to rest in 15 minutes.