since you are using JQuery why not try like this
var xyz = $('.total-box > span').text();
console.log('xyz', xyz);
$('#xyz').val(xyz);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I need to get the total amount of the radio button to pass into a hidden value so I can then pass it to stripe. I can get the total amount to render on the page, but I cannot seem to place it as a value in the hidden field.
This renders to the page.
HTML Snippet
<p class="total-box"><span></span></p>
JS Snippet
var totalDonation = $('.total-box > span');
And this is how I'm trying to place the hidden value:
var xyz = $('.total-box > span').text();
document.getElementById('xyz').value = xyz;
HTML Snippet:
<input type="hidden" id="xyz" name="xyz" value="">
Here is a [CodePen] to see the code and what I'm trying to do. (https://codepen.io/daugaard47/pen/maxrBo?editors=1011)
place this code inside update function
//inside update at the end
totalDonation.text((checkbox.checked ? f(goal) + f(charge) : f(goal)).toFixed(2));
var xyz = $('#total-box').text();
$("#xyz").val(xyz);
var hiddeninput = $("#xyz").val();
Please or to participate in this conversation.