Doing some calculations in the middle of a Form?

# Thread: Doing some calculations in the middle of a Form?

1. Jim Rudnick Guest

## Doing some calculations in the middle of a Form?

Hello all...<BR>&#060;sigh&#062; Seems like it&#039;s my day to wear the Dunce Cap!<BR><BR>I&#039;m simply trying to work out a small calc inside a form, that is, it hasn&#039;t been sent to the dbase yet for storage.<BR><BR>One field, asks for "Quantity" and the other "Cost" <BR><BR>All I wanna do is multiply those two user entered fields together and then *automatically* show it in the next field named "Total."<BR><BR>Seems easy, but I&#039;ve been beating myself up (anyone else wanna take a shot?) all aft on this one. <BR><BR>How do I *use* data the user&#039;s entered before I can use something like &#039;request.form("Cost") etc to do those multiplications and then show it in it&#039;s spot?<BR><BR>Jim

2. Senior Member
Join Date
Dec 1969
Posts
11,334

## RE: Doing some calculations in the middle of a For

Client Side:<BR><BR>textboxvalue = quanitity * price;<BR><BR>Server Side:<BR><BR>INPUT VALUE="&#060;%=Request.form("Quantity") * Request.Form("Price")%&#062;"

3. Tony Guest

## RE: Doing some calculations in the middle of a For

Are they entering the data, or are you just displaying it?

4. Junior Member
Join Date
Dec 1969
Posts
8

## RE: Doing some calculations in the middle of a For

Javascript along the lines of<BR><BR>form.field3.value = form.field1.value*form.field2.value;<BR>

5. Jim Rudnick Guest

## RE: Doing some calculations in the middle of a For

Hmmm...<BR>OakyDokey...tried, but the cell&#039;s still at 0 ?? ie it never updates no matter what numbers you put in the two previous fields?<BR><BR>Here&#039;s the actual code I used...<BR><BR>&#060;INPUT TYPE="text" NAME="Total1" value="&#060;%=Request.Form("QTY1") * Request.Form("Cost1")%&#062;"&#062;<BR><BR>See my mistake?<BR><BR>Jim

6. Senior Member
Join Date
Dec 1969
Posts
11,334

## RE: Doing some calculations in the middle of a For

Are you sure there are values in those fields, and the names are correct? Trust me, that happens all the time... double check &#039;em.<BR><BR>I imagined doing multiplication should automatically convert strings to numbers, but just in case, wrap a CDbl() around both request fields.<BR><BR>What you have looks syntatically correct. No errors are being thrown?

7. Senior Member
Join Date
Dec 1969
Posts
11,334

## Wait a minute...

You ARE submitting this form from a previous page with those two fields, right?

8. Jim Rudnick Guest

## RE: Doing some calculations in the middle of a For

S&#039;matter of fact, the cell just has a 0 in it (thats a zero) and it never changes at all, no matter what I type into the other 2 cells.<BR><BR>Here&#039;s the whole row code too...<BR>&#060;TR bgcolor="white"&#062;<BR> &#060;td&#062;&#060;input type="text" name="Desc1" size="10"&#062;&#060;/td&#062;<BR> &#060;td&#062;&#060;input type="text" name="Part1" size="10"&#062;&#060;/td&#062;<BR> &#060;td&#062;&#060;input type="text" name="Code1" size="10"&#062;&#060;/td&#062;<BR> &#060;td&#062;&#060;input type="text" name="QTY1" size="10"&#062;&#060;/td&#062;<BR> &#060;td&#062;&#060;input type="text" name="Cost1" size="10"&#062;&#060;/td&#062;<BR><BR> &#060;td&#062;<BR> &#060;INPUT type="text" name="Total1" value="&#060;%=Request.Form("QTY1") * Request.Form("Cost1")%&#062;"&#062;&#060;/td&#062;<BR>&#060;/tr&#062;<BR><BR>???????<BR><BR>Jim

9. Senior Member
Join Date
Dec 1969
Posts
11,334

## Ahhh

Yeah, sergeant, you can&#039;t do asp code from the same side as the client without a refresh... you can do javascript, though.<BR><BR>Use some sorta button that says calculate, or something to that effect, and fire this function on the onclick event<BR><BR>function ShowMoney(){<BR> document.formname.Total1.value = QTY1.value * Cost1.value;<BR>}<BR><BR><BR>And put document.formname in front of QTY and Cost for that function.<BR><BR>Unless of course, you&#039;re just submitting the page to itself, the ASP code should work.

10. Jim Rudnick Guest

## RE: Wait a minute...

No, I&#039;m not -- least as far as I understand you ?<BR><BR>Picture an itemized car repair bill. The service mgr is to fill it out item by item, line by line -- which is what I&#039;m trying to create.<BR><BR>The &#060;tr&#062; row that I just showed has NOT yet been sent, ie SUBMITTED. It&#039;s still being worked on by the mgr. They&#039;re to type in (for instance) New Spark Plugs, then Part#:3456yt, then Code:22w4est followed by Quantity:8 followed by Cost:1.29 each.<BR><BR>AT THAT MOMENT, I want the final column, titled TOTAL to show the value of the Quantity * Cost fields, or in this case \$10.32<BR><BR>BUT as yet, the user ain&#039;t pushed SUBMIT...there&#039;s lots more rows to fill out in this SPAN, as well as many other areas to add Labour and 3rdParty stuff too.<BR><BR>If you understand that I&#039;d like these calculations to happen BEFORE the SUBMIT function, then you&#039;ll see that any request.form ("Whatever") offers up no data at all...<BR><BR>Help here guys?<BR><BR>Jim

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•