I’m trying to check if the contain of my input text contains a substring whih is a variable :
here’s my code :
<script>
$("#envoi_search").click(function () {
var contenu = $("#champ").val() ;
$("#envoi_search").click(function() {
$("#result").html('') ;
$('#envoi_search').attr("disabled", "disabled");
$.ajax({
type: "POST",
url: "http://www.edumobile.org/blog/uploads/XML-parsing-data/Data.xml",
data: "{}",
cache: false,
dataType: "xml",
success: function(data) {
$(data).find("Book").each(function () {
var temp = $(this).find("name").text() ;
if (temp.toLowerCase().contenu > -1) {
$("#result").append("<br> Titre : " + temp);
$("#result").append("<br> Auteur : " + $(this).find("address").text());
$("#result").append("<br> Pays : " + $(this).find("country").text());
$('#envoi_search').attr("disabled", "");
}
});
}
});
});
});
</script>
And I don’t know why it doesn’t work. Do you have Any idea about my problem ?
Thanks 🙂
I believe this is what you’re looking for. I removed the inner
.clickevent binding, it was basically setting-up an event binding within the event handler for the same event, making it so that you have to click twice to make the inner event handler work.Also, if you are not on the same domain as
www.edumobile.orgthen you will need to write a proxy script in a server-side language so you can grab the data without cross-domain-policy issues.You were missing the
.search()function when you were checking for the existence of a string within a string.This creates a regular expression based on the value of the
#champinput. The"gi"flags are:g-> global (not really necessary since we’re running a.search()but this can be very useful)i-> ignore caseSome documentation for ya:
.search(): https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/searchRegExp(): https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/RegExp`