JavaScript - Vaciar inputs tipo text cuando el cheqbox no este marcado.

 
Vista:
sin imagen de perfil
Val: 13
Ha aumentado su posición en 13 puestos en JavaScript (en relación al último mes)
Gráfica de JavaScript

Vaciar inputs tipo text cuando el cheqbox no este marcado.

Publicado por Daniel (8 intervenciones) el 04/01/2018 03:01:39
Hola amigo, aqui vengo nuevamente a buscar ayuda, XD de verdad que he aprendido mucho aqui.
Bueno lo que estoy terminando este trabajo de la escuela.
Pero no puedo hacer la ultima parte.

El trabajo es que cuando el cheqbox esta chequeado se copie lo que escribo en el input shippingName en el input
billingName automaticamente y lo mismo con shippingZip con billingZip algo asi como un autocompletar, pero esto ya esta echo.
La otra parte dice que si el cheqbox no esta chequado se borre el value de los inputs. No se me doy a entender. XD
Me pueden ayudar con la segunda parte de la tarea porfa.
Dejo los archivos adjuntos.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 3.162
Oro
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

Vaciar inputs tipo text cuando el cheqbox no este marcado.

Publicado por xve (2100 intervenciones) el 04/01/2018 12:56:51
Hola Daniel, he modificado un poco tu código para generar los eventos necesario para que te funcione...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html><html lang="en">
 <head>
 
  <meta charset="UTF-8">
    <title>Shipping and Billing</title>
    <style>
        input{
          border:1px solid black;
	}
        input:focus{
	   background-color: #E6E6E6;
        }
	fieldset{
 	   margin-bottom: 4%;
	}
    </style>
  </head>
  <body>
	<h1>JavaScript Homework</h1>
        <p>Add the JavaScript code needed to enable auto-complete on this form.  Whenever the checkbox is checked, the code should automatically copy the values from Shipping Name and Shipping Zip into the Billing Name and Billing Zip.  If the checkbox is unchecked, the Billing Name and Billing Zip should go blank.</p>
 
		<form>
        <fieldset>
	           <legend>Shipping Information</legend>
             <label for ="shippingName">Name:</label>
             <input type = "text" name = "Name" id = "shippingName" required><br/>
 
             <label for = "shippingzip">Zip code:</label>
             <input type = "text" name = "zip" id = "shippingZip" pattern = "[0-9]{5}" required><br/>
        </fieldset>
        <input type="checkbox" id="same" name="same" onchange= "billingFunction()"/>
 
        <label for = "same">Is the Billing Information the Same?</label>
        <fieldset>
 	            <legend>Billing Information</legend>
              <label for ="billingName">Name:</label>
              <input type = "text" name = "Name" id = "billingName" required><br/>
	            <label for = "billingzip">Zip code:</label>
              <input type = "text" name = "zip" id = "billingZip" pattern = "[0-9]{5}" required><br/>
	      </fieldset>
 
	 <input type = "submit" value = "Verify"/>
    </form>
  </body>
</html>
 
<script>
window.onload = function(){
	var shipName = document.getElementById("shippingName");
	var shipCode = document.getElementById("shippingZip");
	var zipCode = document.getElementById("billingZip");
	var billName = document.getElementById("billingName");
 
	shipName.addEventListener("keydown",copyContent);
	shipCode.addEventListener("keydown",copyContent);
 
    document.getElementById("same").onchange = copyContent;
 
	function copyContent()
	{
		if(document.getElementById("same").checked)
		{
			billName.value = shipName.value;
			zipCode.value = shipCode.value;
		}
	}
}
</script>

Coméntanos, si te sirve, ok?
Si tienes cualquier duda, ya comentaras...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 13
Ha aumentado su posición en 13 puestos en JavaScript (en relación al último mes)
Gráfica de JavaScript

Vaciar inputs tipo text cuando el cheqbox no este marcado.

Publicado por Daniel (8 intervenciones) el 06/01/2018 00:04:57
hola, muchísimas gracias por tu ayuda y por lo que aprendi, el codigo funciona aun que hay un pequeno bug, no se copia el total de por ejemplo si escribo "hola" en el primer input, en el segundo me sale "hol" es un error bien curioso no crees XD,
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar