/    Sign up×
Community /Pin to ProfileBookmark

Java html form math question?

hello, i have 5 fields in a html form

a = item price ex vat
b = item price inc vat
c = volume ordered
d = Total Ex Vat
e = Total Inc Vat

can anyone help me out with the javascript to do the following;

Either A or B will be supplied by the user. If the user supplies the price ex VAT (@20%) in a then i need B to automatically add the vat on. If the user supplies the price inc VAT then i need field A to update to correspond with the B-vat.

The tricky part is i also need field D and E to update when the user provides C

So it would be A X C = D
and
B X C = E

can anyone who is great at javascript provide me with this/ guide me?

I know html php etc but java is my weak link!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@jalarieJan 27.2012 — Java and JavaScript are totally different things. The names are similar to intentionally cause confusion. You want JavaScript.

Try this:
<i>
</i>
&lt;form method="post" action="javascript:void(0);"&gt;
&lt;div class="form"&gt;
&lt;label for="A"&gt;Item Price Ex Vat:&lt;/label&gt;
&lt;input type="text" size="20" value="0" name="A" id="A" alt="price ex VAT" onfocus="this.select();" /&gt;
&lt;br /&gt;
&lt;label for="B"&gt;Item Price Inc Vat:&lt;/label&gt;
&lt;input type="text" size="20" value="0" name="B" id="B" alt="price inc VAT" onfocus="this.select();" /&gt;
&lt;br /&gt;
&lt;label for="C"&gt;Volume Ordered&lt;/label&gt;
&lt;input type="text" size="20" value="0" name="C" id="C" alt="volume ordered" onfocus="this.select();" /&gt;
&lt;br /&gt;
&lt;input type="button" value="Calculate" title="Submit" onclick="CalcIt();" /&gt;&amp;nbsp;
&lt;input type="reset" value="Reset" title="Reset" /&gt;&amp;nbsp;
&lt;br /&gt;
&lt;label for="D"&gt;Total Ex Vat:&lt;/label&gt;
&lt;input type="text" size="20" value="0" name="D" id="D" alt="total ex Vat" onfocus="this.select();" /&gt;
&lt;br /&gt;
&lt;label for="E"&gt;Total Inc Vat:&lt;/label&gt;
&lt;input type="text" size="20" value="0" name="E" id="E" alt="total inc VAT" onfocus="this.select();" /&gt;
&lt;/div&gt;&lt;!-- form --&gt;
&lt;/form&gt;

<i>
</i>VAT=0.20;
function CalcIt() {
f1=document.forms[0];
VA=f1.A.value;
VB=f1.B.value;
VC=f1.C.value;
if (VB == 0) {
VB=VA*(1+VAT*1);
f1.B.value=VB;
} else {
VA=VB/(1+VAT*1);
f1.A.value=VA;
}
VD=VA*VC;
VE=VB*VC;
f1.D.value=VD;
f1.E.value=VE;
return false;
} // CalcIt
×

Success!

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