Wrox Programmer Forums Display results of a calculation in an online form
 | Search | Today's Posts | Mark Forums Read
 Javascript How-To Ask your "How do I do this with Javascript?" questions here.
 Welcome to the p2p.wrox.com Forums. You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com

May 28th, 2012, 05:58 PM
Registered User
 Points: 5, Level: 1
 Activity: 0%

Join Date: May 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Display results of a calculation in an online form

Hello, after searching on the forum i paste this that is getting me nuts, lets start:
I have a online form that have 2 fields that i need to calculate and show it after clicking the calculate button.

The deal is that I have to use a Excel formula that the client need to be used.
Here is the excel formula I need to use (basically is a rule of thre, if G14 is biger than 0 then we divide in 81, but if is 0 theh we work with 66%):

=IF (G14>0,((J21/100)*100%/81%),((J21/100)*100%/66%))

Here is my script:

<script type="text/javascript">
function calculateTextfinal()
{
var op1=document.getElementById('e1');
var op2=document.getElementById('total1');

var result =document.getElementById('total2');

if(op1.value=="" || op1.value!=parseFloat(op1.value)) op1.value=0;
if(op2.value=="" || op2.value!=parseFloat(op2.value)) op2.value=0;

result.value=0;
result.value=parseInt(result.value);
result.value=parseInt(result.value)+(op1.value * op2.value /0.81);
}
</script>

I guess that the error is in my formula conversion and I need to make an IF the value of op1 (at excel G14) is a cero, any help could be great.

Last edited by ramonolea; May 28th, 2012 at 06:37 PM..

 Similar Threads Thread Thread Starter Forum Replies Last Post Display only Online User vai_rajput BOOK: Professional XMPP Programming with JavaScript and jQuery 1 April 18th, 2011 07:45 PM Calculation using previously entered data in a form wobmat Access VBA 3 July 22nd, 2009 07:17 PM display results carswelljr ASP.NET 2.0 Basics 1 April 19th, 2007 09:46 AM How do I display search results... aspiretech9 PHP How-To 1 April 26th, 2005 10:12 AM How do I display search results... aspiretech9 PHP Databases 1 April 25th, 2005 12:11 PM