i am trying to parse an xml nd comparing its text with input fields but its not working here is the code i have tried..
$('#finish').click(function() {
var email = document.getElementById('email').value
$.ajax({
type: "GET",
url: "test.xml",
dataType: "xml",
success: function(xml) {
$(xml).find('child[name="Email"]').each(function(){
var i = $(this).attr('text');
if(i == email)
alert('email already registered');
else{
activity.SubmitData();
}
});
}
});
});
Html
<input type="text" name="email" id="email" placeholder="Your Email..">
<button id="finish" >Register</button>
XML
<reg>
<user>
<Name> myName</Name>
<Email> myEmail </Email>
<Date> 22/12/2013 </Date>
</user>
</reg>
Try
$('#finish').click(function () {
var email = document.getElementById('email').value
$.ajax({
type: "GET",
url: "test.xml",
dataType: "xml",
success: function (xml) {
//check if any Email element has the entered email as its value
var valid = $(xml).find('Email').filter(function () {
return $.trim($(this).text()) == email
}).length == 0;
//if valid submit the data
if (valid) {
activity.SubmitData();
} else {
alert('email already registered');
}
}
});
});