Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

get checked values with dynamic classes

Posted on 2014-02-06
2
Medium Priority
?
262 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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hi all! Recently there was EE question and the person wanted to have a multi-column textbox <div> selection, so as a first step to answer I provided a link but that was not complete with JavaScript selection, but had a good style sheet. So as a ques…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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)
Suggested Courses

916 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