Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
How to sum data-price and insert it into a hidden input?

I am summing-up the data-price attribute for multiple radio buttons and then trying to insert the result into a hidden input field.

I am able to sum up the price-data within the span in my HTML but I just can't get it to insert into the hidden input...

Should I combine both scripts? and if so, how would I do this?

Here is my HTML for reference...

<input type="radio" style="display:none;" id="cdjs" data-price="90" value="2BA" name="prod">
<label for="cdjs">
  <img src="../../images/prod1.png" style="width:42px;">
  <p>Product 1</p>
</label>


<span id="price"></span>


<input type="hidden" id="hiddenprice" name="price" value=''>

Here is my script that sums up the data-price..

function calcPrice() {
  var price = 0;
  $("input[type=radio][data-price]:checked").each(function(i, el) {
    price += +$(el).data("price");
  });
  $("#price").text(price);
}

$("input[type=radio]").on("change", calcPrice);
calcPrice();

and here is my script that should insert the result into the hidden input..

$(function() {
  $('input').change(function() {
    var checked = $(this).find('input[type=radio]:checked');
    $('#price').html(checked.data('price'));
    $('#hiddenprice').val(checked.data('price'));
  }).change();
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!