Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Last active May 17, 2022 08:49
Show Gist options
  • Save Fhernd/100963165acf1b3d995e5e9439d692ac to your computer and use it in GitHub Desktop.
Save Fhernd/100963165acf1b3d995e5e9439d692ac to your computer and use it in GitHub Desktop.
// Ejercicio 288: Uso del evento onchange sobre el elemento select de HTML.
// Ejercicio 288: Uso del evento onchange sobre el elemento select de HTML.
function seleccionarLenguaje(){
let cbxLenguajes = document.getElementById('cbxLenguajes');
let lenguaje = cbxLenguajes.value;
document.getElementById('lblLenguajeSeleccionado').innerText = `Ud. ha seleccionado el lenguaje ${lenguaje}.`;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>JavaScript - Ejercicio 288</title>
</head>
<body>
<h1>JavaScript - Ejercicio 288</h1>
<span>Seleccione su lenguaje favorito:</span><br>
<select id="cbxLenguajes" onchange="seleccionarLenguaje();">
<option value="JavaScript">JavaScript</option>
<option value="C#">C#</option>
<option value="Java">Java</option>
<option value="PHP">PHP</option>
<option value="Python">Python</option>
</select>
<br>
<span id="lblLenguajeSeleccionado"></span>
<script src="ex288_evento_onchange_select.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment