> I have a form with three checkboxes, and want to set another variable
> depending on which boxes are checked.
>
> The boxes have values of 1, 2, and 4, and I want to add up the values
> of whichever boxes are checked.
>
> The problem is that I'm getting a value of 7 no matter what boxes are
> checked.
> var b1 = document.form1.base1.value;
> var b2 = document.form1.base2.value;
> var b3 = document.form1.base3.value;
Exactly -- you're adding *all the values* regardless of whether the
box is "successful", i.e. checked. :-)
Untested, but something like
var b1 = (document.form.base1.checked)? document.form1.base1.value: 0;
would probably do it.
Alternatively, add event handlers to the checkboxes so they keep a
running total as they're clicked and un-clicked. :-)
I have a form with three checkboxes, and want to set another variable depending on which boxes are checked. The boxes have values of 1, 2, and 4, and I want to...
I have a form with three checkboxes, and want to set another variable depending on which boxes are checked. The boxes have values of 1, 2, and 4, and I want to...
I have a form with three checkboxes, and want to set another variable depending on which boxes are checked. The boxes have values of 1, 2, and 4, and I want to...
I have a form with three checkboxes, and want to set another variable depending on which boxes are checked. The boxes have values of 1, 2, and 4, and I want to...
I have a form with three checkboxes, and want to set another variable depending on which boxes are checked. The boxes have values of 1, 2, and 4, and I want to...
... Exactly -- you're adding *all the values* regardless of whether the box is "successful", i.e. checked. :-) Untested, but something like var b1 =...
... Exactly -- you're adding *all the values* regardless of whether the box is "successful", i.e. checked. :-) Untested, but something like var b1 =...
I have a form with three checkboxes, and want to set another variable depending on which boxes are checked. The boxes have values of 1, 2, and 4, and I want to...
I have a form with three checkboxes, and want to set another variable depending on which boxes are checked. The boxes have values of 1, 2, and 4, and I want to...
... Exactly -- you're adding *all the values* regardless of whether the box is "successful", i.e. checked. :-) Untested, but something like var b1 =...
... Exactly -- you're adding *all the values* regardless of whether the box is "successful", i.e. checked. :-) Untested, but something like var b1 =...
... Exactly -- you're adding *all the values* regardless of whether the box is "successful", i.e. checked. :-) Untested, but something like var b1 =...
I have a form with three checkboxes, and want to set another variable depending on which boxes are checked. The boxes have values of 1, 2, and 4, and I want to...
... Exactly -- you're adding *all the values* regardless of whether the box is "successful", i.e. checked. :-) Untested, but something like var b1 =...
... Exactly -- you're adding *all the values* regardless of whether the box is "successful", i.e. checked. :-) Untested, but something like var b1 =...
... Exactly -- you're adding *all the values* regardless of whether the box is "successful", i.e. checked. :-) Untested, but something like var b1 =...
I have a form with three checkboxes, and want to set another variable depending on which boxes are checked. The boxes have values of 1, 2, and 4, and I want to...
... Exactly -- you're adding *all the values* regardless of whether the box is "successful", i.e. checked. :-) Untested, but something like var b1 =...
I have a form with three checkboxes, and want to set another variable depending on which boxes are checked. The boxes have values of 1, 2, and 4, and I want to...