Solved

get checked values with dynamic classes

Posted on 2014-02-06
2
253 Views
Last Modified: 2014-02-06
I have 8 tables, each table having several radio button groups.  I am trying to get the sum of the checked values for each table, which I am calling 'sections'.  I have 8 input boxes that will be holding the sums for their section.  For the radio buttons in section one I have a class of "S1". The radio buttons in section two have a class of S2, and so on.  I want to loop 8 times to get the totals of each section but I don't know how to reference the checked by class dynamically.

Here is one of the things I have tried:
$('#survey').submit(function()
{
    var result = 0;
    for (var i=1; i<3; i++)
    {
    result = 0;
    $(".S"+i).attr("checked").each(function () {
        result += parseFloat($(this).val());
    });
    $("#sectionTotal"+i').val(result);
    }
    return false; 
});

Open in new window

0
Comment
Question by:KCTechNet
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39840570
$('#survey').submit(function()
{
	var result = 0;
	for (i=1; i<8; i++)
	{
		result = 0;
		$(".S"+i+":checked").each(function () {
			result += parseFloat($(this).val());
		});
		$("#sectionTotal"+i).val(result);
	}
	return false; 
});

Open in new window

0
 

Author Comment

by:KCTechNet
ID: 39840609
worked perfectly.  

thanks.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now