[英]how can i show a different window depending on the option i choose from a selection combo?
And I want to show a different message when I click in one of these options.当我单击其中一个选项时,我想显示不同的消息。
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>
But I can't show anything in my console.log
, what is the problem?但我无法在我的
console.log
中显示任何内容,这是什么问题?
You should use change
rather than onchange
like so .addEventListener('change', function(){
你应该使用
change
而不是onchange
像这样.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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.