Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6842199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:04:13+00:00 2026-05-27T00:04:13+00:00

I have a radio group where I need to do some math calculations based

  • 0

I have a radio group where I need to do some math calculations based on the value of the radio selected, but I also need a way to know my identity value for the SQL record it represents. Normally I would have that stored in the “value” attribute of the radio button.

What I tried to do here is have different ID’s for the same class, and I am trying to figure out how to determine the ID assigned

<input type="radio" class="price" name="price" value="20.00" checked="true" id="1" />
<input type="radio" class="price" name="price" value="385.00" id="2" />
<input type="radio" class="price" name="price" value="504.00" id="3" />

$('.price').change(function() {
calculate();
});

function calculate () {
    var q = $('input#quantity').val();
    var p = $("input[name=price]:checked").val();
    var tot = ((q*p)+parseInt(s));
    $('input#total').val(tot);
};

So in the calculate() function, I get the value but how can I get the ID for the radio button checked? Maybe this is backwards and there is a better way to get my dollar value for the math calculation part and I am open to any suggestions.

TIA – Dan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:04:13+00:00Added an answer on May 27, 2026 at 12:04 am

    So, the way you have your HTML right now, you could use this:

    var id = $("input[name=price]:checked").attr('id');
    

    BUT!

    The id attribute is reserved for the DOM, and on top of that, it can’t shouldn’t start with a number. I might suggest using jQuery.data() instead. Simply add data- to the front of the id attribute you had:

    <input type="radio" class="price" name="price" value="385.00" data-id="2" />
    

    And then retrieve the data-id attribute using the following:

    var id = $("input[name=price]:checked").data('id');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got a group of radio buttons that when clicked need to display
I have several radio buttons that get their value dynamically. Then I have some
I need to get the selected radio button value out of 5 radio buttons.
I have a group box which has some radio buttons. I am trying to
I have a radio box group and I need to select a given radio
I have a group of radio buttons in my Swing application that have a
Hai, I have a group of radio buttons, i could able to pick the
I have a group of three radio buttons. Depending on which radio button is
I have a radio button list and some of the labels are quite long
Ok found some great code on Stack. Have adapted it slightly. But in essence

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.