Hi, I'm newest on WEB developer, I'm sure that the problem is soo easy to resolve (I hope)
I have a simply registry form with HTML5 input's (see MarkUp below) with standard validation as recquired, type, etc.
In addition, I have a AJAX function that call a WebService.....
Then.... what's the problem?
If I make click at button, the call at webservice fire's firstly jumping HTML5 validations....and I need validate the fields and if this ones are OK, then call the WebService.
Form Code [MarkUp]:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Registro.aspx.cs" Inherits="CP_External_Connections.Registro" %>
<!DOCTYPE html>
<html lang="es">
<head runat="server">
<title>Some Title</title>
<link rel="stylesheet" media="screen" href="styles.css" />
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk
/html5.js"></script>
<![endif]-->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#BtnSubmit").click(function (e) {
e.preventDefault();
$.ajax({
type: "POST",
url: "MyWebService.asmx/Method1",
data: "{ _LoginName: '" + $("#Nombre").val() +"', _Nombre: '" + $("#Nombre").val() + "', _Apellidos: '" + $("#Apellidos").val() +"', _Password: '" + $("#Password").val() + "', _Mail: '" + $("#Email").val()+"' }",
dataType: 'json',
contentType: "application/json; charset=utf-8",
async: false,
success: function (data) {
alert(data.d); // show the string that was returned, this will be the data inside the xml wrapper
},
error: function (e) {
alert("Error text.");
}
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server" class="contact_form" method="post">
-
My Form
- <label for="Nombre">Nombre:</label>
<input type="text" name="_Nombre" id ="Nombre" placeholder="Juan" required />
- <label for="Apellidos">Apellidos:</label>
<input type="text" name="_Apellidos" id ="Apellidos" placeholder="Pérez Díaz" required />
- <label for="email">Email:</label>
<input type="email" name="email" id ="Email" placeholder="MiEmail@ejemplo.com" required />
- <label for="password">Contraseña:</label>
<input type="text" name="_Password" id="Password" placeholder="MiEmail@ejemplo.com" required />
- <button class="submit" type="submit" id="BtnSubmit" value="CrearUsuario">Registrarse</button>
</form>
</body>
</html>