Hi neebie here to javascript, I been trying to get this code to compile but am running into syntax errors any pointers on how to correct it would be massively appreciated!
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
<script type = "text/javascript">
//Searchbar
$(document).ready(function() {
$("#searchbar").on("keyup", function() {
$.ajax({
type: "GET",
url: "links.xml",
dataType: "xml",
success: xmlParser
});
});
});
function xmlParser(xml) {
var searchFor = $("#searchbar").val();
var reg = new RegExp(searchFor, "i");
$(xml).find("link").each(function() {
var title = $(this).find("title").text();
var titleSearch = title.search(reg);
$("#xmloutput").empty();
if (titleSearch > -1) {
$("#xmloutput").append("<a href=" + $(this).find("href").text +">"+ searchFor.text + "</a>");
}
});
</script>
My html and CSS is fine but am stuggling with this a bit! Basically I’m trying to match the hyperlink to its associated title (found in the links.xml file) as searched for via the html #searchbox, and then output any clickable results to the #xmloutput box on my html page.
The xml file is pretty basic in structure just containing the page title and html page address (all stored in the same local folder as the xml).
<pages>
<link>
<title></title>
<href></href>
</link>
</pages>