Hi everybody,
I'm new on jQuery (in fact programming I'm novice) and need some guide to solve something I have to...
I'm building a form that have two fields which converts values into hashed strings using Alex Weber's sha256 jQuery plugin. In addition I need to compare it with the ones stored in a xml, and permit form submit only if user input and xml values are equal.
The plugin works and I can get data from the xml, but i'm getting problems when I try to compare the data. That's the code I wrote:
- <!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>
<script src="hash.js"></script>
</head>
<body>
<p>
<form>
<label>Validador</label>
<input type="text" value="" id="telefono" required />
<input type="text" value="" id="fecha" required />
</form>
</p>
<p>
<div id="salidaXML">
<div class="telefono"></div>
<div class="nacimiento"></div>
<div class="mansaje"></div>
</div>
</p>
</body>
<script type="text/javascript">
$(document).ready(function() {
// No queremos ningun campo vacio
if ($('#telefono').val() == "" || $('#fecha').val() == "")
{
alert("No puedes dejar ningun campo vacio!");
}
else // Guardamos los dato hasheados
{
TelHash = $.sha256($('#telefono').val());
FechaHash = $.sha256($('#fecha').val());
$.ajax({
type: "GET",
url: "hash.xml",
dataType: "xml",
success: function(xml) {
$(xml).find('usuario').each(function(){
nombre = $(this).find('nombre').text();
telefono = $(this).find('telefono').text();
nacimiento = $(this).find('nacimiento').text();
if (telefono == TelHash || nacimiento == FechaHash)
{
$('<h3 class="nombre"></h3>').html(nombre).appendTo('#salidaXML');
$('<div class="telefono"></div>').html(telefono).appendTo('#salidaXML').before('<strong>Telefono:</strong><br/>');
$('<div class="nacimiento"></div>').html(nacimiento).appendTo('#salidaXML').before('<strong>Fecha de nacimiento:</strong><br/>').after('<br/>');
}
else
{
alert("Nooop");
}
});
}
});
}
});
</script>
</html>
The issue is that it doesn't apply the condition and shows me the alert despite the data that I put in the form fields. Obviously I'm doing something wrong, but I can't see where.
Thanks in advance for everybody that pay atention to this post, and i will be grateful if somebody helps me to find the mistake.