What is the recommended method to create a new form field when a radio button is clicked in PHP?

When a radio button is clicked in PHP, you can use JavaScript to dynamically create a new form field based on the selected radio button. This can be achieved by listening for the click event on the radio button and then using JavaScript to append a new input field to the form.

<script>
document.addEventListener('DOMContentLoaded', function() {
    document.getElementById('radioButton').addEventListener('click', function() {
        if(this.checked) {
            var newInput = document.createElement('input');
            newInput.setAttribute('type', 'text');
            newInput.setAttribute('name', 'newField');
            document.getElementById('form').appendChild(newInput);
        }
    });
});
</script>