I am running a script referenced in an HTML document and everything works very well, except the validation of the inputs in the form
I'm trying something like this:
<!--Documento index.html-->
<!DOCTYPE html>
<html lang="es-co">
<head>
<meta charset="utf-8"/>
<title>Documento Prueba</title>
</head>
<body>
<form name="formulario" id="form1" autocomplete="off">
<label>Valor</label>
<input type="text" id="valor" placeholder="Digita un valor" required/>
<input type="submit" id="subcapturar" value="Capturar">
</form>
<div id="mensaje"></div>
<script type="text/javascript" src="js/jquery-3.2.1.js"></script>
<script type="text/javascript" src="js/main.js"></script>
</body>
</html>
The JS code:
//Documento main.js
$("#subcapturar").click(function(event){
var mivalor=$("#valor").val();
$("#mensaje").text("El valor capturado fue :" + mivalor);
event.preventDefault();
});
This script works well, the problem is that the sending is done without performing the required validation of the input id = value.
Try changing the event in JS
$("#form1").submit(function(event){
var mivalor=$("#valor").val();
$("#mensaje").text("El valor capturado fue :" + mivalor);
});
More did not work. Does anyone have a solution?
I do not see that this is failing in my logic Thanks for the help