Im trying to print the Book title , price and date from in xml file with ajax using javascript. I spend almost two days on it and watched some video on youtube to figure it out i could not .I do not know where im doing wrong if You could help me with it you making my day .Thank you .
$(document).ready(function() {
$("#find").click(function() {
var book = $("#book").val();
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.status == 200) {
document.getElementById('forPrice').innerHTML = 'Test1';
var i;
var xmlDoc = xhttp.responseXML;
var x = xmlDoc.getElementsByTagName("book");
for (i = 0; i < x.length; i++) {
catalog + = xmlDoc[i].getElementsByTagName("price")[0].childNodes[0].nodeValue);
document.getElementsById("#forPrice").innerHTML(catalog);
xmlDoc[i].getElementsByTagName("title")[0].childNodes[0].nodeValue);
document.getElementsById("#forBookInformation").innerHTML(catalog);
xmlDoc[i].getElementsByTagName("data")[0].childNodes[0].nodeValue);
document.getElementsById("#forPublishDate").innerHTML(catalog);
});
}
};
xhttp.open("POST", "books.xml", true);
xhttp.send();
})
})
<?xml version="1.0"?>
<catalog>
<book>
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<price>44.95</price>
<date>2000-10-01</date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
<book>
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<price>5.95</price>
<date>2000-12-16</date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
<book>
<author>Corets, Eva</author>
<title>Oberon's Legacy</title>
<price>5.95</price>
<date>2001-03-10</date>
<description>In post-apocalypse England, the mysterious
agent known only as Oberon helps to create a new life
for the inhabitants of London. Sequel to Maeve
Ascendant.</description>
</book>
<book>
<author>Thurman, Paula</author>
<title>Splish Splash</title>
<price>4.95</price>
<date>2000-11-02</date>
<description>A deep sea diver finds true love twenty
thousand leagues beneath the sea.</description>
</book>
<book>
<author>Knorr, Stefan</author>
<title>Creepy Crawlies</title>
<price>4.95</price>
<date>2002-10-01</date>
<description>An anthology of horror stories about roaches,
centipedes, scorpions and other insects.</description>
</book>
</catalog>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Books</title>
<style type="text/css">
table,
td {
border: 1px solid black;
}
</style>
<script src="jquery-1.11.2.js"></script>
<script src="p3.js"></script>
</head>
<body>
<h1>Books</h1>
<h2>Book Price</h2>
<form action="" method="post">
<select name="book" id="book">
<option value="XML Developer's Guide">XML Developer's Guide</option>
<option value="Midnight Rain">Midnight Rain</option>
<option value="Oberon's Legacy">Oberon's Legacy</option>
<option value="Splish Splash">Splish Splash</option>
<option value="Creepy Crawlies">Creepy Crawlies</option>
</select>
Select a book to see the price
<br>
<br>
<input type="button" id="find" value="Find!">
</form>
<div id="forPrice"></div>
<h2>Author Names and Book Titles</h2>
<div id="forBookInformation"></div>
<h2>Book Publish Date</h2>
<div id="forPublishDate"></div>
<body>
</html>
ajax using javascript. I spend almost two days on it and watched some video on youtube to figure it out i could not .I do not know where im doing wrong if You could help me with it you making my day .Thank you .
catalog + =syntax error, unexpected token =