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

Need the Sum of 4 items to be part of Webpage

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
I'm new to CF and Db's; I'm creating an invoice page (with CF)to print out. It needs to add 4 items together to write to the MS Access field.

Currently, I have to add everything up and type it into the "total" field (on one of the CF pages I made).

Is there a way HTML, CF, or the DB file itself can do this?
...maybe even Javascript? (I dont know JS but I can probably figure it out if you have something simple)

Tank you in advance!!

 
Yes, I'm certain it can be done.

Can you give a real quick example. I'm not quite understanding what data you want to write to the DB. Kevin
slanek@ssd.fsi.com

"Life is what happens to you while you're busy making other plans."
- John Lennon
 
Without really knowing what you are looking for here are some ides.

javascript
Code:
<head>
	<title>Invoice</title>
<script type=&quot;text/javascript&quot;>
<!--
	function total_fields()
	{
		document.MyForm.value_total.value = (eval(document.MyForm.value_one.value)+
											eval(document.MyForm.value_two.value)+
											eval(document.MyForm.value_three.value)+
											eval(document.MyForm.value_four.value));
	}

-->
</script>
</head>
<body>
<form name=&quot;MyForm&quot; action=&quot;Action_Page&quot; method=&quot;post&quot;>
	<input type=&quot;Text&quot; name=&quot;value_one&quot; value=&quot;5&quot;><br>
	<input type=&quot;Text&quot; name=&quot;value_two&quot; value=&quot;10&quot;><br>
	<input type=&quot;Text&quot; name=&quot;value_three&quot; value=&quot;15&quot;><br>
	<input type=&quot;Text&quot; name=&quot;value_four&quot; value=&quot;20&quot;><br>
	<input type=&quot;Text&quot; name=&quot;value_total&quot;><br><br>
	<input type=&quot;Button&quot; name=&quot;btn_clac&quot; value=&quot;Calculate Total&quot; onclick=&quot;total_fields();&quot;>
	<input type=&quot;Submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot; onclick=&quot;total_fields();&quot;>
</form>


</body>

coldfusion
Code:
<cfset form.one=14>
<cfset form.two=6>
<cfset form.three=20>
<cfset form.four=4>
<cfset total=form.one+form.two+form.three+form.four>

<cfoutput>#total#</cfoutput>

not sure if these help at all. If they do not please be a little more specific. :-) Randall2nd
 
Kevin:

Yes, thank you.

I have an &quot;edit&quot; page that pulls info from the Access DB and populates only some of the fields in this form (this is the way I was instructed to update records). On this page, you can change the info that was populated and add new info into fields that are blank. Submitting the form then does a CFUPDATE to the record.

So, the additional info I want to include into the record for the CFUDATE is to type in 4 amounts and then a tax amount and then the total. But currently, I have to add them up manually and type in the total into the field, and this is where I'd like something to calculate the total for me and have it entered into the field for the CFUPDATE.

I hope this help and I am very grateful for your replies ...this is Sweet.

-Tony
 
Code:
This is the form:
<INPUT TYPE=&quot;text&quot; NAME=&quot;val1&quot;>
<INPUT TYPE=&quot;text&quot; NAME=&quot;val2&quot;>
<INPUT TYPE=&quot;text&quot; NAME=&quot;val3&quot;>
<INPUT TYPE=&quot;text&quot; NAME=&quot;val4&quot;>

Submit this form to the next page which does this:
<CFSET total = Evaluate((val1 + val2 + val3 + val4) * tax)>

Now you can use your new variable &quot;total&quot; in your CFUPDATE
<CFUPDATE>
   UPDATE myTable
   SET total = #total#
</CFUPDATE>
Does this make any sense? This is a very basic version of what you're saying, but I think it might get you going in the right direction. Let me know if you need more help. Kevin
slanek@ssd.fsi.com

&quot;Life is what happens to you while you're busy making other plans.&quot;
- John Lennon
 
Randall, Here's my equivalent scenario:

<CFQUERY name=&quot;edit_details&quot; datasource=&quot;tickets&quot;>
SELECT * FROM tickettable
WHERE ticket=#ticketnum#
</CFQUERY>

<form action=&quot;update.cfm&quot; method=&quot;post&quot;>
<input type=&quot;Text&quot; name=&quot;value_one&quot; value=#value_one#>
<input type=&quot;Text&quot; name=&quot;value_two&quot; value=#value_two#>
<input type=&quot;Text&quot; name=&quot;value_three&quot; value=#value_three#>
<input type=&quot;Text&quot; name=&quot;value_four&quot; value=#value_four#><br>
Total Is:<input type=&quot;Text&quot; name=&quot;value_total&quot; value=#value_total#>
<input type=&quot;Submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;>
</form>


The update.cfm does a CFUPDATE;
#ticketnum# was passed from the last web page.

I need the value of value_total to be calculated automatically. I tried the <CFSET> but couldn't get it to set a variable = to a field read thru the CFQUERY (like <CFSET value_one=#value_one#>.

Thanks again in advance!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top