Solved

get checked values with dynamic classes

Posted on 2014-02-06
2
259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

635 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