House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  JQuery

summing radio buttons

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
This worked for me:
Raymond Camden
06/14/11 11:31 A
>> total += parseInt($(this).val());
Gerald Guido
06/14/11 11:39 A
Um - no idea. :)
Raymond Camden
06/14/11 11:47 A
Note:
Phillip Senn
06/14/11 12:29 P
That's a good point there. Thanks PS!
Raymond Camden
06/14/11 12:40 P
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Michael Dinowitz
06/14/2011 11:09 AM

This should be simple. I have a few radio buttons and when each is clicked, I want a text field to show the sum of the values of the clicked buttons. This should be simple but I can't seem to get it to work. Here's the code I'm using:     <script type="text/javascript" src="/jquery/jquery.js"></script>     <script type="text/javascript">         $("input[type=radio]").change(function() {             var total = 0;             $("input[type=radio]:checked").each(function() {                 total += $(this).val();             });             $("#totalSum").val(total);         });     </script> <form action="radiotest.cfm"  method="post"> duss1<br> <input type="radio" name="duss1" value="1" class="duss">1 <input type="radio" name="duss1" value="0" class="duss">0 <br> duss2<br> <input type="radio" name="duss2" value="1" class="duss">1 <input type="radio" name="duss2" value="0" class="duss">0 <br> <input type="text" name="totalSum" id="totalSum" value=""> <input type="submit"> </form> I've tried it using ".duss" rather than "input[type=radio]", .click rather than .change, and "input[name='totalSum']" rather than "#totalSum". What am I doing wrong? Thanks

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Raymond Camden
06/14/2011 11:30 AM

You forgot to wrap it in document.ready. The code fails because nothing matches at the time it is executed. ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Raymond Camden
06/14/2011 11:30 AM

You also want to parseInt your values - I'm getting string additions, not numeric additions. ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Raymond Camden
06/14/2011 11:31 AM

This worked for me:   <script type="text/javascript">    $(document).ready(function() {           $("input[type=radio]").change(function() {        console.log("ran");            var total = 0;            $("input[type=radio]:checked").each(function() {                total += parseInt($(this).val());            });            $("#totalSum").val(total);        });       });    </script> ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Gerald Guido
06/14/2011 11:39 AM

>>   total += parseInt($(this).val()); Q: Is there any advantages to using parseint() as opposed to Number()? Thanx G! > parseInt -- Gerald Guido http://www.myinternetisbroken.com "ONE  TWO  THREE  FOUR!!!" -- Dee Dee Ramone

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Michael Dinowitz
06/14/2011 12:05 PM

That was one of my test variables. ParseInt, ParseFloat, no parse function, etc. So that's 2 answers. :) Thanks again > > You also want to parseInt your values - I'm getting string additions, > not numeric additions. > >

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Phillip Senn
06/14/2011 12:29 PM

Note: parseInt(str) will assume octal if the leading digit is a 0. Crockford says to always use parseInt(str,10). On Tue, Jun 14, 2011 at 12:04 PM, Michael Dinowitz < mdinowit@houseoffusion.com> wrote: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Raymond Camden
06/14/2011 12:40 PM

That's a good point there. Thanks PS! ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Michael Dinowitz
06/14/2011 12:03 PM

I knew it was something so simple that I could not see it. Thanks ----- Excess quoted text cut - see Original Post for more -----


<< Previous Thread Today's Threads Next Thread >>

Search jquery

May 22, 2013

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
       1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31   

Designer, Developer and mobile workflow conference