<div class="top"> <label for="locationName">Location:</label> <input type="text" class="locationName" id="locationName" maxlength="20" readonly> </div> <li> <input type="radio" id="selected_location_ac" name="selected_location" value="ATLANTIC_CITY" onchange="findSelection('selected_location')"> <label for="selected_location_ac">Atlantic City</label> </li> <li> <input type="radio" id="selected_location_ac" name="selected_location" value="LAS_VEGAS" onchange="findSelection('selected_location')"> <label for="selected_location_ac">LAS Vegas</label> </li>JavaScript
function findSelection(rad_name) { const locationName = document.querySelector("#locationName"); let rad_val = document.querySelector('input[name=' + rad_name + ']:checked'); locationName.value = (rad_val ? rad_val.value : "") return (rad_val ? rad_val.value : ""); }Estoy tratando de mostrar el valor de la etiqueta en el cuadro de texto de entrada.
La persona hará clic en un botón de radio y luego el cuadro de texto de entrada mostrará su selección. No quiero que muestre el valor del botón de opción, ya que puede ser difícil entender lo que significa.