Y quiero mostrar un mensaje diferente cuando hago clic en una de estas opciones.
document.getElementById("specialityAppointmentSelection").addEventListener('onchange', function(){ let specialityAppointmentSelection = document.getElementById("specialityAppointmentSelection"); let specialityOption = specialityAppointmentSelection.value; console.log(specialityOption); if(specialityOption === "1"){ console.log("medicina"); } else { console.log("enfermería"); } }); <p>Selecciona el tipo de cita que desee: </p> <select id = "specialityAppointmentSelection"> <option value = "1">Medicina</option> <option value = "2">Enfermería</option> </select> Pero no puedo mostrar nada en mi console.log , ¿cuál es el problema?
Debería usar change en lugar de onchange así .addEventListener('change', function(){
document.getElementById("specialityAppointmentSelection").addEventListener('change', function(){ let specialityAppointmentSelection = document.getElementById("specialityAppointmentSelection"); let specialityOption = specialityAppointmentSelection.value; console.log(specialityOption); if(specialityOption === "1"){ console.log("medicina"); } else { console.log("enfermería"); } }); <p>Selecciona el tipo de cita que desee: </p> <select id = "specialityAppointmentSelection"> <option value = "1">Medicina</option> <option value = "2">Enfermería</option> </select>