El siguiente orograma usa el tipo de elemento
select
.
1 | <!DOCTYPE html> |
2 | <html lang="es"> |
3 | |
4 | <head> |
5 | <meta charset="UTF-8"> |
6 | <meta name="viewport" |
7 | content="width=device-width"> |
8 | <title>Recomendaciones</title> |
9 | </head> |
10 | |
11 | <body> |
12 | <form |
13 | action="javascript:procesa()"> |
14 | <h1>Recomendaciones</h1> |
15 | <p> |
16 | <label> |
17 | Género |
18 | <select id="inGenero" required> |
19 | <option value=""> |
20 | -- Selecciona -- |
21 | </option> |
22 | <option value="pop"> |
23 | Pop |
24 | </option> |
25 | <option value="reg"> |
26 | Reguetón |
27 | </option> |
28 | </select> |
29 | </label> |
30 | </p> |
31 | <p> |
32 | <button>Recomendar</button> |
33 | </p> |
34 | </form> |
35 | <script> |
36 | function procesa() { |
37 | const genero = inGenero.value |
38 | const resultado = |
39 | recomienda(genero) |
40 | alert(resultado) |
41 | } |
42 | |
43 | /** @param {string} genero */ |
44 | function recomienda(genero) { |
45 | if (genero === "pop") { |
46 | return "Para el pop te " + |
47 | "recomiendo a Dua Lipa." |
48 | } else if (genero === "reg") { |
49 | return "Para el reguetón te " + |
50 | "recomiendo a Bad Bunny." |
51 | } |
52 | } |
53 | </script> |
54 | </body> |
55 | |
56 | </html> |
La especificación técnica del elemento
select
está en
https://html.spec.whatwg.org/multipage/form-elements.html#the-select-element