/    Sign up×
Community /Pin to ProfileBookmark

Checkbox values

Right, I’m trying to add a checkbox that will return a value of 1 when unchecked and a value of 1.05 if checked, any ideas? Here’s the form it’s going in!

[CODE]<form name=”floorcalculator”>
<table>
<tr><td>
Sqm:
</td><td>
<input type=”text” name=”sqm” size=”5″ value =”0″> <input type=”checkbox” name=”wasteage”> Include 5% wasteage
</td></tr>
</table>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=”button” name=”b1″ value=”Calculate” onClick=calculate()><input type=”reset” /><br><br>
You will need <input type=”text” name=”quantityneeded” size=”3″ value =”0″> packs.<br><font color=”#509950″><b><i>Enter this quantity below if you wish to purchase.</i></b></font>

</form>

<script type=”text/javascript”>

function calculate() {
var A = document.floorcalculator.sqm.value
var B = document.floorcalculator.wasteage.value
var C = Math.ceil ((A*B)/2.5)
document.floorcalculator.quantityneeded.value = C
}

</script>[/CODE]

Massive thanks to anyone who can help!

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@rtretheweyApr 25.2012 — Checkbox elements do not return explicit values. You can only test them to see if the 'checked' property is true or false and use that information to set the value of other variables.
Copy linkTweet thisAlerts:
@xelawhoApr 25.2012 — how about:

[CODE]var B = document.floorcalculator.wasteage.checked?1.05:1;[/CODE]
Copy linkTweet thisAlerts:
@sparkiesuzeauthorApr 25.2012 — Ahh perfect thank you so much xelawho!! ?
×

Success!

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