in the Author and Title fields a user may enter strings like:
contains Ad or contains Jack or contains ack etc..
and my html table will display the appropriate information (ie books where the title (or author, if we're talking about the Author field..) contains the given substring.. But it's not working.. What am I doing wrong? I keep getting contains is not defined
in my error console..
(by the way, all of my conditionals var author=...
etc. definitions should be place before if(moz)
? Otherwise this will only work in Firefox right?)
<html>
<script type="text/javascript">
function filterTable(f)
{
var xmlDoc = loadXML("books.xml");
var stylesheet = loadXML("books.xsl");
var moz = (typeof document.implementation.createDocument != 'undefined');
var ie = (typeof window.ActiveXObject != 'undefined');
if (moz)
{
var nsResolver = stylesheet.createNSResolver( stylesheet.ownerDocument == null ? stylesheet.documentElement : stylesheet.ownerDocument.documentElement);
var value = stylesheet.evaluate("//xsl:template[@match='/']//xsl:for-each", stylesheet, nsResolver, XPathResult.ANY_UNORDERED_NODE_TYPE, null);
var author = document.getElementById("inauthor").value;
var title = document.getElementById("intitle").value;
var filter = "";
if (author != "")
{
if(contains(author,"contains"))
{
filter = filter + "contains(author," + "'" + author.substr(10) + "'" + ")";
}
else filter= filter + "author='" + author.substr(1) + "'";
}
if (title != "")
{
if (filter != "") filter = filter + " and ";
if(contains(title,"contains"))
{
filter = filter + "contains(title," + "'" + title.substr(10) + "'" + ")";
}
else
{
filter = filter+ "title='" + title.substr(1) + "'";
}
}
if (filter != "") filter = "[" + filter + "]";
value.singleNodeValue.setAttribute("select", "books/scifi"+filter);
var proc = new XSLTProcessor();
proc.importStylesheet(stylesheet);
var resultFragment = proc.transformToFragment(xmlDoc, document);
document.getElementById("target4").appendChild(resultFragment);
}
else if (ie)
{
var value = stylesheet.selectSingleNode("//xsl:template[@match='/']//xsl:for-each");
value.setAttribute("select", "books/scifi"+filter);
document.write(xmlDoc.transformNode(stylesheet));
}
}
</script>
<center>
<table border="1" cellpadding="8">
<tr><td>
</br>
<form>
<center>
<b> search by </b>
Author(s): <input type="text" name="authors" id="inauthor"/>
Title: <input type="text" name="title" id="intitle" />
</br></br>
<input type="button" value="Display" onClick="filterTable(this.form)"/>
</center>
</form>
</td></tr>
</table>
</center>
</body>
</html>