Click to See Complete Forum and Search --> : trying to create calculator


dunger
01-16-2003, 02:14 PM
Hello,
This is my first inquiry to this forum and I'm hoping someone can help me. I know little to nothing about JS but learn everything web-wise by looking at and borrowing what others have done before me (which I appreciate greatly).

Currently I am charged with creating a calculator function where the user inputs one number to produce three calculations based on different numbers. I've copied what I have so far in hopes that someone can help determine my problem. The first calculation works, but the next two do not.

<FORM name="formx">
<p align="left">My investment is $
<input type=text size=10 value=100 name="a">

</p>
<p align="left">When the calculation is done, </p>
<p align="left">I will receive: $
<input type "number" value=0 name="ans" size=10>
in #1 bonds,
<input type="hidden" value=".37037037" name="b">
<input type="button" value=" Calculate " onClick="a_times_b(this.form)" name="button">
</p>
<p align="left">and: $
<input type "number" value=0 name="ans2" size=10>
in #2 bonds,
<input type="hidden" value=".62932963" name="c">
<input type="button" value=" Calculate " onClick="a_times_c(this.form)">
</p>
<p align="left">and: <input type "number" value=0 name="ans2" size=10> in extras.
<input type="hidden" value=".02310198" name="d">
<input type="button" value=" Calculate " onClick="a_times_d(this.form)">
</p>
</FORM>

It is based on a JS calculator I found in the calculators section of http://javascript.internet.com/
I'm working in Dreamweaver 4.

I'd appreciate any assistance.
Debbie

Dan Drillich
01-16-2003, 03:49 PM
Please try the following crude code -


<SCRIPT LANGUAGE="JavaScript">
function a_times_b(){
document.formx.ans.value = parseInt(document.formx.a.value) * document.formx.b.value;
}

function a_times_c(){

document.formx.ans2.value = parseInt(document.formx.a.value) * document.formx.c.value;
}


function a_times_d(){

document.formx.ans3.value = parseInt(document.formx.a.value) * document.formx.d.value;
}



</SCRIPT>




<FORM name="formx">
<p align="left">My investment is $
<input type=text size=10 value=100 name="a">

</p>
<p align="left">When the calculation is done, </p>
<p align="left">I will receive: $
<input type "number" value=0 name="ans" size=10>
in #1 bonds,
<input type="hidden" value=".37037037" name="b">
<input type="button" value=" Calculate " onClick="a_times_b();" name="button">
</p>
<p align="left">and: $
<input type "text" value=0 name="ans2" size=10>
in #2 bonds,
<input type="hidden" value=".62932963" name="c">
<input type="button" value=" Calculate " onClick="a_times_c();">
</p>
<p align="left">and: <input type "number" value=0 name="ans3" size=10> in extras.
<input type="hidden" value=".02310198" name="d">
<input type="button" value=" Calculate " onClick="a_times_d();">
</p>
</FORM>



Cheers,
Dan

dunger
01-17-2003, 08:25 AM
Dan,
Your 'crude' solution worked right away.
This forum is a great support for non-techies like me.
Thank you, thank you.
Debbie

Dan Drillich
01-17-2003, 08:49 AM
Debbie,

Here is a bit less crude code :) -


<SCRIPT LANGUAGE="JavaScript">

function mul(r,p1,p2){
r.value = parseInt(p1) * p2;
}

</SCRIPT>




<FORM name="formx">
<p align="left">My investment is $
<input type=text size=10 value=100 name="a">

</p>
<p align="left">When the calculation is done, </p>
<p align="left">I will receive: $
<input type "number" value=0 name="ans" size=10>
in #1 bonds,
<input type="hidden" value=".37037037" name="b">
<input type="button" value=" Calculate "

onClick="mul(document.formx.ans,document.formx.a.value,document.formx.b.value);"

name="button">
</p>
<p align="left">and: $
<input type "text" value=0 name="ans2" size=10>
in #2 bonds,
<input type="hidden" value=".62932963" name="c">
<input type="button" value=" Calculate "

onClick="mul(document.formx.ans2,document.formx.a.value,document.formx.c.value);">
</p>
<p align="left">and: <input type "number" value=0 name="ans3" size=10> in extras.
<input type="hidden" value=".02310198" name="d">
<input type="button" value=" Calculate "

onClick="mul(document.formx.ans3,document.formx.a.value,document.formx.d.value);">
</p>
</FORM>




Cheers,
Dan

dunger
01-17-2003, 09:22 AM
Thanks Dan,
That solution also works.

Debbie

dunger
01-20-2003, 09:47 AM
Now that the calculator is working and live, here's the link to the page (choose calculator link):
http://www.swp.com/investor.html

Thanks again, everyone here is impressed.

Debbie