/    Sign up×
Community /Pin to ProfileBookmark

:confused: Calculation!!!

[code=php]

<script type=”text/javascript”>
function CalcPercnt(val, f) {
//val: Percentage Field value
//f: form which percent1 is in

if (!val == “”){
f.amt1.value = (f.Cost.value * (val / 100 + 1)).toFixed(2)
}
}
</script>

[/code]

I need to calculate profit and the amount in percentage(profit margin).The profit is in dollar ($).This code only calculate the amount =cost*percentage.Now,I hope someone can help me to change this codes and get the profit in ($).

The output of this codes is(example)::

Cost:………………. Percentage:………………. Amount:………………….

Cost:10 Percentage:5 Amount:10.5O

Now,i need a code that can give the output like this:

Cost:10 Percentage:5 Amount:10.5O Profit:$0.50

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterMay 20.2005 — I recieved your PM, here's a stylish code that will suit the purpose well:
[code=html]
<html>
<title>Sales Price</title>
<script type="text/javascript">
function CalcPercnt(f) {
var val=f.percent1.value
//val: Percentage Field value
//f: form which percent1 is in
if (!val == ""){
var daTotal=(f.Cost.value * (val / 100 + 1)).toFixed(2)
f.amt1.value = daTotal
f.pro1.value=(daTotal-f.Cost.value).toFixed(2)
}
}
</script>
<style type="text/css">
.ro{
background-color: royalblue;
color: white;
border: 2px solid skyblue;
}
</style>
</head>
<body>
<form name="Imp">
<table cellpadding=0 cellspacing=0>
<tr><td>Cost:</td><td><input name="Cost" type="text" size=20></td></tr>
<tr><td>Percentage:</td><td><input name="percent1" type="text" size=20></td></tr>
<tr><td>Amount:</td><td><input name="amt1" type="text" readonly class="ro" size=20></td></tr>
<tr><td>Profit:</td><td><input name="pro1" type="text" readonly class="ro" size=20></td></tr>
<tr><td></td><td><input onclick="CalcPercnt(this.form)" type="button" value="Calculate"><input type="reset" value="Clear"></td></tr>
</table>
</form>
</body>
</html>
[/code]


Would you mind contributing to my guestbook and/or interactive story in return? It's not too much to ask, is it? ?

thanks!
×

Success!

Help @inventive spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...