/    Sign up×
Community /Pin to ProfileBookmark

calculations

I have an edit box in which i write a number (e.g 50). In another i have the number(e.g 5) and in another the number (e.g.3). By pressing a button the value 42 will appear(50 – 5 – 3 = 42)in another edit box. Always subtracting from the first edit box.

I know that i must use the function recalc() but since i am new i have some difficulties.

Can anyone please make my life easier ?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Dan_DrillichJan 22.2003 — Please try -

<i>
</i>&lt;SCRIPT LANGUAGE="JavaScript"&gt;

function sub(r,p1,p2){
r.value = parseInt(p1) - parseInt(p2);
}

&lt;/SCRIPT&gt;


&lt;FORM name="formx"&gt;
&lt;p align="left"&gt;My total is
&lt;input type=text size=10 value=50 name="a"&gt;

&lt;/p&gt;
&lt;p align="left"&gt;Please substract: <br/>
&lt;input type "number" value=0 name="b" size=10&gt;
&lt;input type="button" value=" Calculate "
onClick="sub(document.formx.a,document.formx.a.value,document.formx.b.value);" name="button"&gt;
&lt;/p&gt;

&lt;/FORM&gt;


Pretty close.

Cheers,

Dan
Copy linkTweet thisAlerts:
@Dan_DrillichJan 22.2003 — and a bit cleaner -

<i>
</i>&lt;SCRIPT LANGUAGE="JavaScript"&gt;

function sub(p1,p2){
return parseInt(p1) - parseInt(p2);
}

&lt;/SCRIPT&gt;




&lt;FORM name="formx"&gt;
&lt;p align="left"&gt;My total is
&lt;input type=text size=10 value=50 name="a"&gt;

&lt;/p&gt;
&lt;p align="left"&gt;Please substract: <br/>
&lt;input type "number" value=0 name="b" size=10&gt;
&lt;input type="button" value=" Calculate " onClick="a.value=sub(a.value,b.value);" name="button"&gt;
&lt;/p&gt;

&lt;/FORM&gt;


Cheers,

Dan
×

Success!

Help @lhsths 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,
)...