Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jorgemunive/984015505b47f02835c3da56b565b152 to your computer and use it in GitHub Desktop.
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
<!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