IS this what you want??

function showValues(theForm) {
  var currVal = document.getElementById("ptotal");
  var sum = 0;
  for(var i=0;i<theForm.elements.length;i++) {
   if(theForm.elements[i].checked)
    sum +=  parseInt(theForm.elements[i].value);
  }
  alert(sum);
}

Pascal

> -----Original Message-----
> From: Greg Morphis [mailto:[EMAIL PROTECTED]
> Sent: 31 August 2004 18:34
> To: CF-Talk
> Subject: Re: SOT : Keeping JS Count
>
> this is what I have
> function showValues(theForm) {
>   currVal = document.getElementById("ptotal");
>   sum = 0;
>   for(i=0;i<theForm.elements.length - 1;i++) {
>    sum +=  parseInt(theForm.elements[i].value);
>   }
>   alert(sum);
> }
>
> Unfortunately the radios have a value of 0 and a value of 1.
> So this adds up 0 + 1 per radio and returns 1.
> How do I make it add up only whats selected, not both values?
> Maybe a radio isnt the right way of doing this? I'm open to any
> suggestions.
>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to