Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compute value of one field from two others on same form

Status
Not open for further replies.

Dijital

MIS
Mar 15, 2002
47
US
If I have the following code:

(not exact, just a rough idea)

<%
sub update()
Dim intstart, intend, intresult

intstart= *FILL IN THE BLANKS*
intend= *FILL IN THE BLANKS*
intresult = datediff(&quot;n&quot;,intstart, intend)

end sub
%>

<form name=&quot;summary&quot;>

<input name=&quot;start&quot; type=&quot;text&quot; value=&quot;12/1/2000 12:00 AM&quot; onchange=&quot;call update()&quot;>
<input name=&quot;end&quot; type=&quot;text&quot; value=&quot;12/1/2000 12:15 AM&quot; onchange=&quot;call update()&quot;>
<input type=&quot;text&quot; value=&quot;<% =intresult %>&quot;>

</form>

It's the *FILL IN THE BLANKS* section that I can't figure out. I'm trying to assign the start and end values into the variables to compute the elapsed time.
How do I reference the form on the current page to obtain those values.
I can use the recordset data, but if change it, it's going to use the old value.
Do I have to have the form submit to the same page to compute the value, or is there a jscript or vbscript solution to this?

Jim
 
&quot; onchange=&quot;call update()&quot;> &quot;

This is client side code. In order for the browser to execute this, you need to use VBScript or JavaScript with the <script type=&quot;JavaScript&quot;> </script> or <script type=&quot;VBScript&quot;> </script> tags.
 
okay I understand how to call it, but how do I reference the other form text fields within the sub?

Jim
 
If I understand correctly, you are not sure how to reference the HTML variables in your sub. Here's an example that might give you an idea (provided you use the script tags as baddos suggested above):
Code:
sub update()
Dim intstart, intend, intresult

intstart= document.summary.start.value
intend= document.summary.end.value
intresult = datediff(&quot;n&quot;,intstart, intend)

end sub

I should qualify that example as saying that it is using javascript syntax, not sure if VBScript syntax is exactly the same, but the idea should be similar. Hope that at least gives you an idea. (This would also give you the values on the page itself, not the recordset data as you were worried about.)


-----------------------------------------------------------------------------------------------------
&quot;If you can't explain something to a six-year-old, you really don't understand it yourself.&quot;
-- Albert Einstein
 
Chopstik,

Exactly! I cant get the sab to assign the proper values that are currently in the textboxes.

The idea is that if the time changes in either the start or end time field, it raises the onchange, calls the update() sub, crrent values for the start and end are passed to the variable, datediff'ed, and the result is placed in the duration.

I dont know javascript, just vbscript, and I'm still having trouble referencing the fields...

Bueller, Bueller, Bueller -I think he's sick sir.

jim
 
Did you try to use the syntax above? I've quickly perused a few examples elsewhere and it seems (on the surface) that the syntax may be very similar. If not, let me know and I'll see if I can find some other more concrete examples.

-----------------------------------------------------------------------------------------------------
&quot;If you can't explain something to a six-year-old, you really don't understand it yourself.&quot;
-- Albert Einstein
 
Chopstik,

I spent about 2 hours last night trying to sort it out... got precisely no where. Kept getting &quot;object Expected&quot; and &quot;character missing ';'&quot; errors.

I decided to solve it a different way; I dropped duration off the summary, and I'm going to break down the outages into multiple records (depending on applications and systems affected) with individual time periods and have it take the earliest start time and latest end time to compute the duration on the following page.

Nothing like an administrative upgrade to resolve a pain in the head issue! Thanks for all the help though!

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top