What is the best practice for updating prices in a shop system using PHP, especially when dealing with radio buttons for component selection?

When dealing with radio buttons for component selection in a shop system using PHP, the best practice for updating prices is to use JavaScript to dynamically update the price based on the selected component. This can be achieved by assigning unique values to each radio button and using event listeners to capture the selected value and update the price accordingly.

<script>
document.addEventListener('DOMContentLoaded', function() {
    const radioButtons = document.querySelectorAll('input[type="radio"]');
    const priceElement = document.getElementById('price');

    radioButtons.forEach(function(button) {
        button.addEventListener('change', function() {
            if (this.checked) {
                let price = parseFloat(this.value);
                priceElement.textContent = '$' + price.toFixed(2);
            }
        });
    });
});
</script>