Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
how to make calculation for some text boxes
Old 01-13-2011, 03:15 AM how to make calculation for some text boxes
Junior Talker

Posts: 3
Trades: 0
hye..im new here..now, im doing my final year project..this is my page code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>testing calculation</title>
<style type="text/css">
.style2 {
text-align: left;
}
.style3 {
font-family: "Bauhaus 93";
font-size: xx-large;
background-color: #C0C0C0;
}
</style>
</head>

<body style="background-color: #C0C0C0">

<div class="style2">

CAR CC:
<input name="carcc" type="text" /><br />
SPEED&nbsp;&nbsp;
: <input name="speed" type="text" /><br />
TRAVEL OCCURRENCES&nbsp;&nbsp;&nbsp; : <input name="occurrence" type="text" /><br />
PASSENGERS: <input name="passenger" type="text" /><br />
DISTANCE: <input name="distance" type="text" />
</div>
<form method="post">
<div class="style2">
<input name="submit" type="submit" value="CALCULATE RESULT" class="style3" /></div>
</form>

</body>

</html>


..my problem now is i want to make a calculation for all the values in the text boxes and show the result under the CALCULATE RESULT button..my formula for this calculation is like this:
[-20.955 + (0.0013 * carcc) + (0.1463 * speed) + (0.6766 * occurrence) + (0.04 * passenger) + (0.1481 * distance)]
thanks for your help =)
kidphantom is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-14-2011, 10:12 PM Re: how to make calculation for some text boxes
Experienced Talker

Posts: 39
Name: Day
Trades: 0
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
 
<head> 
<meta content="en-us" http-equiv="Content-Language" /> 
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> 
<title>testing calculation</title> 
<style type="text/css"> 
.style2 { 
text-align: left; 
} 
.style3 { 
font-family: "Bauhaus 93"; 
font-size: xx-large; 
background-color: #C0C0C0; 
} 
</style>
<script type="text/javascript">
function calculate_result()
{
var ccc=document.getElementById("carcc").value;
var spd=document.getElementById("speed").value;
var occ=document.getElementById("occurrence").value;
var psg=document.getElementById("passenger").value;
var dst=document.getElementById("distance").value;
document.getElementById("result").value=(-20.955 + (0.0013*ccc) + (0.1463*spd) + (0.6766*occ) + (0.04*psg) + (0.1481*dst));
}
</script>
</head> 
<body style="background-color: #C0C0C0"> 
<div class="style2"> 
CAR CC: <input id="carcc" type="text" /><br /> 
SPEED : <input id="speed" type="text" /><br /> 
TRAVEL OCCURRENCES: <input id="occurrence" type="text" /><br /> 
PASSENGERS: <input id="passenger" type="text" /><br /> 
DISTANCE: <input id="distance" type="text" /> 
</div> 
<div class="style2"> 
<input id="submit" type="submit" value="CALCULATE RESULT" class="style3" onclick="calculate_result()" /></div> 
RESULT: <input id="result" type="text" />
</body> 
</html>
Maybe something like this is what your looking for? I've only started learning javascript 3 days ago so I'm still very new but it seems to work when I tested it.

Last edited by DayliDesign; 01-14-2011 at 10:13 PM..
DayliDesign is offline
Reply With Quote
View Public Profile
 
Old 02-01-2011, 01:37 AM Re: how to make calculation for some text boxes
Average Talker

Posts: 23
Name: Ale Abby
Location: Victoria , Taxes
Trades: 0
Great sharing, I always make mistake developing calculator, hope it will me.
__________________
The financial institute are now have many facilities to satisfy the desires of customers need,
Please login or register to view this content. Registration is FREE
is one them.
aleabby is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to how to make calculation for some text boxes
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.61919 seconds with 12 queries