[jQuery] Filtering through XML for Live Search
Hi there,
I am trying to create a live search by filtering through XML.
The XML structure is as follows:
<studentlist>
<student>
<sid>1</sid>
<sname>Joe Bloggs</sname>
<sform>7B</sform>
<syear>7</syear>
</student>
<student>
<sid>2</sid>
<sname>John Doe</sname>
<sform>7B</sform>
<syear>7</syear>
</student>
etc...
</studentlist>
The html input is:
<input name="studentName" id="studentName" type="text"
onkeyup="suggestStud($('#studentName'))" />
and then below that is a div called 'suggest'
The javascript I've come up with so far is:
$(function() {
$.ajax({type: "GET",url: "
studentsxml.php", dataType: "xml", success:
function(xmlData)
{
xml = xmlData;
}
});
});
function suggestStud(name){
$("sname:contains("+name+")", xml).each(function(i){
$('#suggest').html($(this).text()+"<br/>");
});
}
However it's not returning a list of names that contain the input. Any
pointers?
Many thanks