Php or JavaScript calculator needed ASAP

Started on the old forum in January 2013 · view the original in the archive · old links redirect here

3 replies · 350 views · started 13 years ago · 1 min read

2 participants
Thanks48 Newbie · 3 posts #1

I have taught myself programming in certain languages over the years. Still haven't quite figured out out how to make this calculator work the way I want it. Here is the formula that I want the calculator to perform. External image (may be gone) I want it to be in a column type setup like so

Left side: Carbs: <input box> (should times by two) Calories: <input box> Protein: <input box> (should times by three)

Right side of form: Total: ( Total of all three on left side times 2.66 )

Anyone that can get me a script for this I would greatly appreciate it.

something else Fellow · 2,296 posts #2
<script type="text/javascript">
function somethingElse()
{
var cb = document.getElementById("carbs").value;
var cl = document.getElementById("calories").value;
var p = document.getElementById("protein").value;
document.getElementById("output").value = ((cb*2)+cl+(p*3))*2.66;
}
</script>
<form>
carbs: <input type="text" id="carbs" onkeyup="somethingElse();"/>
calories: <input type="text" id="calories" onkeyup="somethingElse();"/>
protein: <input type="text" id="protein" onkeyup="somethingElse();"/>
Result: <input type="text" id="output"/>
</form>
Thanks48 Newbie · 3 posts #3

Thank you so much I learn something new everyday in programming. I'm going to try one more thing with this if I can't figure it out you mind if I ask you.

something else Fellow · 2,296 posts #4

Sorry i messed up the first code i will edit it 🙂

Sure 🙂

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close