dyingjoy
11-11-2004, 06:38 PM
The code below works fine with the weight fields holding the following values:
<input name="weight4" type="Text" value="" size="5"> (active4 isn't checked)
<input name="weight3" type="Text" value="33.34" size="5">
<input name="weight2" type="Text" value="33.33" size="5">
<input name="weight1" type="Text" value="33.33" size="5">
The perctotal = 100%
but when I change the field values to
<input name="weight4" type="Text" value="0.01" size="5">
<input name="weight3" type="Text" value="33.33" size="5">
<input name="weight2" type="Text" value="33.33" size="5">
<input name="weight1" type="Text" value="33.33" size="5">
The perctotal = 99.999999999999999998%
I have found a few other combinations that end up with a faulty total, but I can't figure out what is causing the issue.
var perctotal = 0;
if (qform.active4.checked) {
perctotal = (parseFloat(perctotal) + parseFloat(qform.weight4.value));
}
if (qform.active3.checked) {
perctotal = (parseFloat(perctotal) + parseFloat(qform.weight3.value));
}
if (qform.active2.checked) {
perctotal = (parseFloat(perctotal) + parseFloat(qform.weight2.value));
}
if (qform.active1.checked) {
perctotal = (parseFloat(perctotal) + parseFloat(qform.weight1.value));
}
if (perctotal != 100) {
alert("Active questions total " + perctotal + "%\nThe total must equal 100%");
return false;
}
Any ideas as to what is causing this issue?
Thanks,
Doug
<input name="weight4" type="Text" value="" size="5"> (active4 isn't checked)
<input name="weight3" type="Text" value="33.34" size="5">
<input name="weight2" type="Text" value="33.33" size="5">
<input name="weight1" type="Text" value="33.33" size="5">
The perctotal = 100%
but when I change the field values to
<input name="weight4" type="Text" value="0.01" size="5">
<input name="weight3" type="Text" value="33.33" size="5">
<input name="weight2" type="Text" value="33.33" size="5">
<input name="weight1" type="Text" value="33.33" size="5">
The perctotal = 99.999999999999999998%
I have found a few other combinations that end up with a faulty total, but I can't figure out what is causing the issue.
var perctotal = 0;
if (qform.active4.checked) {
perctotal = (parseFloat(perctotal) + parseFloat(qform.weight4.value));
}
if (qform.active3.checked) {
perctotal = (parseFloat(perctotal) + parseFloat(qform.weight3.value));
}
if (qform.active2.checked) {
perctotal = (parseFloat(perctotal) + parseFloat(qform.weight2.value));
}
if (qform.active1.checked) {
perctotal = (parseFloat(perctotal) + parseFloat(qform.weight1.value));
}
if (perctotal != 100) {
alert("Active questions total " + perctotal + "%\nThe total must equal 100%");
return false;
}
Any ideas as to what is causing this issue?
Thanks,
Doug