Click to See Complete Forum and Search --> : Calling an ASP Function from HTML


championc
08-20-2006, 06:21 PM
Hi all,

I have two fields (out of about 20) in a form which accept times. I have an ASP function to subtract one time from the other to get the difference.

I want to be able to display the difference in a text box (or label) when these have been entered and before the rest of the fields are completed.

From the second field, is it possible to write an onBlur command (or something else) that will run my ASP function

<input type="text" name="myTextBox" size="20" onBlur=myASPFunction()>
or something like this?

My ASP Function is

strSTART = (FormatDateTime(rsLogfile("START"), 4))
strEND = (FormatDateTime(rsLogfile("END"), 4))
strSTARTx = (DatePart("n", rsLogfile("START")))
strENDx = (DatePart("n", rsLogfile("END")))
strTimeHrs = (DateDiff("h", strEND, strSTART))
strTimeMin = (DateDiff("n", strEND, strSTART) Mod 60)
IF strSTARTx < strENDx THEN
strTimeHrs = strTimeHrs - 1
END IF
IF strTimeMin < 10 THEN
strTimeMin = "0" & strTimeMin
END IF
strTimeDiff = strTimeHrs & ":" & strTimeMin

I assume I can then do something like

this.form.timediff.value = strTimeDiff


Cormac

ahk2chan
08-20-2006, 10:27 PM
I don't think you can call an ASP function in your Javascript, since ASP is server-side and Javascript is client-side. So when Javascript is executing, ASP code has already been executed.

So you probably need to implement the time different function in Javascript.

Terrorke
08-21-2006, 04:26 AM
Yep ahk2chan is wright.
You can't do this in an ASP script (or you have to submit the page back to the server).
I think you will have better luck trying this in Javascript.

Here is a link you can use to calculate the difference in Javascript :
http://www.javascriptkit.com/javatutors/datedifference.shtml