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.

PHP Forum


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



Freelance Jobs

Reply
how to make calculation for some text boxes
Old 01-13-2011, 03:14 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-13-2011, 07:24 AM Re: how to make calculation for some text boxes
phpdasan's Avatar
Experienced Talker

Posts: 37
Name: Karthick B
Trades: 0
Here is your solution in javascript

PHP 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-alignleft;
}
.
style3 {
font-family"Bauhaus 93";
font-sizexx-large;
background-color#C0C0C0;
}

#resultDIV{font-family:"Arial";font-size:14px;font-weight:bold;color: #E02E1C;margin-top:1em;}
</style>
<
script type="text/javascript">
var 
calculate = function()
{
 
//
 
var carcc document.getElementById('carcc').value;
 var 
speed document.getElementById('speed').value;
 var 
occurrence document.getElementById('occurrence').value;
 var 
passenger document.getElementById('passenger').value;
 var 
distance document.getElementById('distance').value;
 var 
result = (-20.955 + (0.0013 carcc) + (0.1463 speed) + (0.6766 occurrence) + (0.04 passenger) + (0.1481 distance));
document.getElementById('resultDIV').innerHTML result;
}
</script>

</head>

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

<div class="style2">

CAR CC:
<input name="carcc" id="carcc" type="text" /><br />
SPEED&nbsp;&nbsp;
: <input name="speed" id="speed" type="text" /><br />
TRAVEL OCCURRENCES&nbsp;&nbsp;&nbsp; : <input name="occurrence" id="occurrence" type="text" /><br />
PASSENGERS: <input name="passenger" id="passenger" type="text" /><br />
DISTANCE: <input name="distance" id="distance" type="text" />
</div>
<form method="post">
<div class="style2">
<input name="submit" type="button" value="CALCULATE RESULT" class="style3" onclick="calculate();" />
</div>
<div id="resultDIV"></div>
</form>
</body>
</html> 
__________________
There is no secret ingredient.
phpdasan 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.26706 seconds with 12 queries