Solved

get checked values with dynamic classes

Posted on 2014-02-06
2
252 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I have answered several questions lately that were solved utilizing the power of jQuery's AJAX functions, so I thought I would write an article demonstrating the ease of use. Why should I use jQuery as opposed to regular JavaScript? Now I know…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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)

707 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

18 Experts available now in Live!

Get 1:1 Help Now