How can you set up different text fields to display based on the radio button selected in PHP?

To set up different text fields to display based on the radio button selected in PHP, you can use JavaScript to show/hide the text fields dynamically. You can achieve this by creating a function that listens for changes in the radio button selection and then shows or hides the corresponding text fields accordingly.

<script>
function showTextField() {
    var selectedValue = document.querySelector('input[name="radio"]:checked').value;
    if(selectedValue === 'option1') {
        document.getElementById('text1').style.display = 'block';
        document.getElementById('text2').style.display = 'none';
    } else if(selectedValue === 'option2') {
        document.getElementById('text1').style.display = 'none';
        document.getElementById('text2').style.display = 'block';
    }
}
</script>

<form>
    <input type="radio" name="radio" value="option1" onclick="showTextField()"> Option 1 <br>
    <input type="radio" name="radio" value="option2" onclick="showTextField()"> Option 2 <br>
    
    <input type="text" id="text1" style="display:none;"> Text Field 1 <br>
    <input type="text" id="text2" style="display:none;"> Text Field 2 <br>
</form>