Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda