Dia 33
This commit is contained in:
62
Practicas/Practicas JS/DOM 05/ejercicio05_DOM.html
Normal file
62
Practicas/Practicas JS/DOM 05/ejercicio05_DOM.html
Normal file
@@ -0,0 +1,62 @@
|
||||
<!Doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Compra caja JAVASCRIPT</title>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
// Escribir mensaje en el input
|
||||
function mensaje() {
|
||||
// Obtener datos de los inputs
|
||||
let nombre = document.getElementById("nombre").value;
|
||||
let material = document.getElementById("material").value;
|
||||
let tamano = document.querySelector("[name=tamano]:checked").value;
|
||||
let comentarios = document.getElementById("comentarios").value;
|
||||
|
||||
// Ver en consola
|
||||
console.log(nombre, material, tamano, comentarios);
|
||||
// Escribir mensaje en el input
|
||||
document.getElementById("respuesta").value = "Hola " + nombre + " has pedido una caja de " + material + " de tamaño " + tamano + ". " + comentarios;
|
||||
}
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
|
||||
<p>Nombre cliente</p>
|
||||
<input type="text" name="nombre" id="nombre">
|
||||
<p>Material de la caja
|
||||
<!-- Lista de selección -->
|
||||
<select name="material" id="material">
|
||||
<option value="madera">Madera</option>
|
||||
<option value="metal">Metal</option>
|
||||
<option value="plastico">Plástico</option>
|
||||
</select></p>
|
||||
|
||||
<p>Seleccione un tamaño para la caja</p>
|
||||
<br/>
|
||||
<input type="radio" value="diminuta" name="tamano">Diminuta<br>
|
||||
<input type="radio" value="mediana" name="tamano" checked>Mediana<br>
|
||||
<input type="radio" value="grande" name="tamano">Grande<br>
|
||||
<br>
|
||||
<p>Comentarios</p>
|
||||
<!-- Área de texto -->
|
||||
<textarea name="opinion" rows="10" cols="60" id="comentarios"></textarea>
|
||||
<br>
|
||||
|
||||
<input type="submit" value="Enviar" onclick="mensaje()">
|
||||
<input type="text" name="respuesta" id="respuesta" size="80">
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<br>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
BIN
Practicas/Practicas JS/DOM 05/ejercicio05_DOM.png
Normal file
BIN
Practicas/Practicas JS/DOM 05/ejercicio05_DOM.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
56
Practicas/Practicas JS/DOM 05/index.html
Normal file
56
Practicas/Practicas JS/DOM 05/index.html
Normal file
@@ -0,0 +1,56 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<script src="./js/main.js"></script>
|
||||
<title>Document</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div style="display: flex; flex-direction: column; gap: 1rem; max-width: 500px; margin: 0 auto;">
|
||||
<div style="display: flex; flex-direction: column;">
|
||||
<label for="nombre">Nombre del cliente</label>
|
||||
<input type="text" name="nombre" id="nombre" required>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; gap: 2px;">
|
||||
<label for="tipoCaja">Material de la caja</label>
|
||||
<select name="tipoCaja" id="tipoCaja" required>
|
||||
<option value="Madera" selected>Madera</option>
|
||||
<option value="Metal">Metal</option>
|
||||
<option value="Plastico">Plastico</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; flex-direction: column;">
|
||||
<p style="margin: 0px;">Seleccione unas dimensiones para la caja:</p>
|
||||
<div>
|
||||
<input type="radio" name="dimensiones" id="diminuta" value="diminuta" readonly checked>
|
||||
<label for="dimensiones">Diminuta</label>
|
||||
</div>
|
||||
<div>
|
||||
<input type="radio" name="dimensiones" id="mediana" value="mediana">
|
||||
<label for="dimensiones">Mediana</label>
|
||||
</div>
|
||||
<div>
|
||||
<input type="radio" name="dimensiones" id="grande" value="grande">
|
||||
<label for="dimensiones">Grande</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; flex-direction: column;">
|
||||
<label for="comentarios">Comentarios</label>
|
||||
<textarea name="comentarios" id="comentarios" cols="30" rows="10"></textarea>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button onclick="generaPedido()"> Enviar </button>
|
||||
<span id="resultado" style="border: 1px solid black;"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
11
Practicas/Practicas JS/DOM 05/js/main.js
Normal file
11
Practicas/Practicas JS/DOM 05/js/main.js
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
function generaPedido(){
|
||||
let txtNombre = document.getElementById("nombre").value;
|
||||
let slbMaterial = document.getElementById("tipoCaja").value;
|
||||
let chkDimensiones = document.querySelector('input[name="dimensiones"]:checked').value;
|
||||
let txtComentarios = document.getElementById("comentarios").value;
|
||||
let txtResultado = document.getElementById("resultado");
|
||||
|
||||
let resultado=` ${txtNombre} ha pedido una caja de ${slbMaterial} con unas dimensiones ${chkDimensiones}. ${txtComentarios}`
|
||||
txtResultado.textContent=resultado;
|
||||
}
|
||||
Reference in New Issue
Block a user