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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying calculation results 1

Status
Not open for further replies.

sinistapenguin

Technical User
Jan 21, 2004
31
GB
Hi everyone

I am having a stab at creating a web application and have hit a sticking point.

I have a page which will (eventually) insert a record into the Order Line table.

It looks a bit like this:

StockCode----Qty----UnitPrice----Total
Code1---------2------10----------- ****

I want the page to calculate the total and display it where the **** is. I am currently using ASP w/ VBScript.

If possible I would like it to update this when the Qty field is changed, but if I need to submit the Qty etc back to the server to calculate the total I don't really mind.

The calculation itself isn't the real problem, it's how and where I insert the relevant code in order to get the result to display where I want it.

It should be simple because it's a single page, not even adding up repeating data entries!!

Any suggestions (or fully fledged solutions) gratefully received.

Thank

Ben
 
do your calculations and get your total:
Code:
<%
varTotal = varQty * varPrice
%>

then highlight the **** on your page switch to code view and change the highlighted ****'s to <%=varTotal%>

Off you go

Cheech

[Peace][Pipe]
 
Hi Cheech

Thanks for that, the only other question I have is how I pass the values from the Qty and UnitPrice text fields to the calculation?

Thanks again

Sinista!!
 
submit the form to the same page when quantities are changed. this way you can just use request.form(&quot;qty&quot;)

what method are you using to pass the qty ordered to this page? querystring, form?

On the order page the user selects what they want to buy. lets say this has a dropdown called ddItem. They submit this page to your quantity page.
Qauntity page selects from database the item code and price that match the ddItem selection. Now just after the recordset add something like
Code:
<%
varPrice = rsRecordset.Fields.Item(&quot;price&quot;).value
varQty = request.form(&quot;varQty&quot;)
if varQty = &quot;&quot; then varQty = 1 end if
varTotal = varPrice * varQty
%>

Now your form should end up looking like this

<form action=&quot;thispage.asp&quot; method=&quot;post&quot;>
<input name=&quot;varQty&quot; type=&quot;text&quot; value=&quot;<%=varQty%>&quot;><br>
<input name=&quot;varPrice&quot; type=&quot;text&quot; value=&quot;<%=varPrice%>&quot;><br>
<input name=&quot;varTotal&quot; type=&quot;text&quot; value=&quot;<%=varTotal%>&quot;><br>
<input name=&quot;Submit&quot; type=&quot;submit&quot; value=&quot;Submit&quot;>

Or something along those lines.

Cheech


[Peace][Pipe]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top