/    Sign up×
Community /Pin to ProfileBookmark

Calculation Problem

I have a Field, which is of number type.

and other 4 fields also, which is number data type.

So i want to write JavaScript, Suppose if i enter value 21 in first field, then it display in other four field like that–

when i enter —

Enter:- 21

1st field – 5
2nd field – 5
3rd field – 5
4th field – 6

when i enter —

Enter:- 22

1st field – 5
2nd field – 5
3rd field – 6
4th field – 6

Please help me..

Thanks

Abhi

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@KorApr 28.2006 — I guess that this is what you want:
<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;meta http-equiv="Content-Style-Type" content="text/css"&gt;
&lt;meta http-equiv="Content-Script-Type" content="text/javascript"&gt;
&lt;script type="text/javascript"&gt;
function calculate(f){
var n = Number(f['inp'].value)
var d=parseInt(n/4,10);//integer division result
var r=n%4;//remainder
for(var i=3;i&gt;=0;i--){
f['res'+i].value=(r&gt;0)?d+1:d;
r--;
}
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form&gt;
input a number&lt;input name="inp" type="text"&gt;
&lt;br&gt;
&lt;br&gt;
&lt;input name="res0" type="text"&gt;&lt;br&gt;
&lt;input name="res1" type="text"&gt;&lt;br&gt;
&lt;input name="res2" type="text"&gt;&lt;br&gt;
&lt;input name="res3" type="text"&gt;
&lt;br&gt;
&lt;input type="button" value="Calculate" onclick="calculate(this.form)"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@abhit_kumarauthorApr 28.2006 — thanks alot
×

Success!

Help @abhit_kumar 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 5.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...