Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

get checked values with dynamic classes

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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
This article discusses how to create an extensible mechanism for linked drop downs.
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)

704 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