Last active
July 17, 2021 18:01
-
-
Save Jorgemunive/984015505b47f02835c3da56b565b152 to your computer and use it in GitHub Desktop.
Simple javascript script adding subtracting value input, Code taken from: https://www.youtube.com/watch?v=1TU-ssZSuYQ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="es"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
</head> | |
<body> | |
<form action="" name="ejemplo15" method="POST"> | |
Producto XYZ: | |
<input type="text" name="Cantidad" value="1" size="2" > | |
<input type="button" value="aumentar" onclick="ejemplo15.Cantidad.value++;validaCantidad(this.form)" > | |
<input type="button" value="disminuir" onclick="ejemplo15.Cantidad.value--;validaCantidad(this.form)" > | |
</form> | |
<script> | |
// valor0 = ejemplo15.Cantidad.value; | |
// console.log(valor0); | |
function validaCantidad(form){ | |
if(form.Cantidad.value < 1) | |
{ | |
form.Cantidad.value = 1; | |
alert("no puede comprar menos de un producto"); | |
} | |
if(form.Cantidad.value >10){ | |
form.Cantidad.value = 10; | |
alert("la cantidad máxima de productos a comprar es de 10 productos") | |
} | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment