/    Sign up×
Community /Pin to ProfileBookmark

How do I use this calculation throughout the form?

Hi Guys

Forgive me moderators for this second post but I think maybe my first post was unclear.

I have the following calculation and want to use it to calculate the rest of the form.

<html><head>
<script>
function calc(){
var chkd;
var count = 0;
if(document.qtyFrm.c1.checked){chkd=document.qtyFrm.c1.value; count=count+1;}
if(document.qtyFrm.c2.checked){chkd=document.qtyFrm.c2.value; count=count+1;}
if(count==2){alert(“Check only one, please.”); return false;}
document.qtyFrm.qtyTotal.value=parseInt(document.qtyFrm.qty.value)*chkd;
}
</script>
</head><body>
<form name=”qtyFrm”>
<p>
<input type=text name=”qty” onkeypress=”calc()”>
<br>
130:
<input type=checkbox name=”c1″ value=”130″ onclick=”return calc()”>
<br>
1300:
<input type=checkbox name=”c2″ value=”1300″ onclick=”return calc()”>
<br>
<input type=text name=”qtyTotal”>
</p>
<p>
<input type=”text” name=”textfield”>
<br>
<input type=”checkbox” name=”checkbox” value=”checkbox”>
<br>
<input type=”checkbox” name=”checkbox2″ value=”checkbox”>
<br>
<input type=”text” name=”textfield2″>
</p>
</form></body></html>

How do I calculate the last fields and checkboxes using the above calculation?

Thank you in advance for your assistance.

Kind regards
Darryn

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@JackTheTripperApr 23.2003 — Is this what you're looking for?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``

<html><head>
<script>
function calc(boxName1,boxName2){
var chkd;
var count = 0;
if(document.getElementById(boxName1).checked){chkd=document.getElementById(boxName1).value; count=count+1;}
if(document.getElementById(boxName2).checked){chkd=document.getElementById(boxName2).value; count=count+1;}
if(count==2){alert("Check only one, please."); return false;}
document.qtyFrm.qtyTotal.value=parseInt(document.qtyFrm.qty.value)*chkd;
}
</script>
</head><body>
<form name="qtyFrm">
<p>
<input type=text name="qty" onkeypress="calc('c1','c2')">
<br>
130:
<input type=checkbox name="c1" value="130" onclick="return calc('c1','c2')">
<br>
1300:
<input type=checkbox name="c2" value="1300" onclick="return calc('c1','c2')">
<br>
<input type=text name="qtyTotal">
</p>
<p>
<input type="text" name="textfield">
<br>
<input type="checkbox" name="checkbox" value="checkbox" onclick="return calc('checkbox','checkbox2')">
<br>
<input type="checkbox" name="checkbox2" value="checkbox" onclick="return calc('checkbox','checkbox2')">
<br>
<input type="text" name="textfield2">
</p>
</form></body></html>
×

Success!

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