View Full Version : Script Generated Button Code Creating Corrupted Code

Jan 1st, 2010, 08:32 PM
I'm trying to get my Client Side Firefox DHTML app to display a list of eBooks. For this, i have the following files


textbooks.html is my DHTML app
eBooks.txt is the Library file with a listing of all of my eBooks.
Inside of eBooks.txt is the following data:

FirstBook.txt to ThirdBook.txt are my actual ebooks.

The problem that i'm having is that When i try to click on any buttons other than the FirstBook button, i get the following error:

Error: unterminated string literal
Source File: file:///F:/Textbooks.html
Line: 1, Column: 10
Source Code:

So, unlike clicking on the FirstBook button, these other buttons do not load the eBook data into the DIV for displaying the eBook data.

I use the DOM insepector to checkout the DOM of the button code, and it seems like whitespace maybe is the problem. However, i have removed whitespace from the HTMLdata string, and that's not fixing the problem.

did i forget something silly? LOL

i'm using FireFox 3.5 to develop this App. So obviously this will not work with anything other than Gecko Based browsers.

here is my HTML code:

<script language="JavaScript">
var eBookLibrary = "eBooks.txt";
var SystemPath = "f:" + String.fromCharCode(92)

function Init()
// Initialize the eBook reader
document.getElementById("EbookCanvas").style.visibility = "hidden";
document.getElementById("EbookToolbar").style.visibility = "visible";
document.getElementById("FileManager").style.visibility = "visible";

// Load the List of eBooks in the Library

function UpdateEbookList()
// Update the Library of Ebooks
alert("Updating eBook Library");

// Go back to the File Manager, and Reload the List of Ebooks

function LoadBookList()
// This will load the list of books that are available
var EbookList = LoadFromDisk(SystemPath + eBookLibrary);
var EbookListArray = EbookList.split(",");

for(var x = 0; x < EbookListArray.length -1; x++)
// Strip the Filename Extension off of the eBook File Name
// The Name of the Book is always the first Index in the Array
var BookName = EbookListArray[x].split(".");
// Remove the weird whitespace - it screws things up...i think...
BookName[0] = BookName[0].replace(/(^\s*|\s*$)/g, "");

var HTMLdata = HTMLdata + "<input type='button' value='" + "FirstBook" + "'" + " onClick=LoadEbook('" + EbookListArray[x] + "');><br>";

// For some ****ed up reason the first string always generates an 'undefined' even though it's nonsense
// So just delete that from the HTMLdata string, because it's just ugly - LOL
HTMLdata = HTMLdata.replace("undefined", "");
HTMLdata = HTMLdata.replace("", " ");

// Write the HTML data to the DIV
document.getElementById("FileManager").innerHTML = HTMLdata;

function LoadEbook(EbookName)
// Hide the File Manager and Show the Ebook Canvas
document.getElementById("FileManager").style.visibility = "hidden";
document.getElementById("EbookCanvas").style.visibility = "visible";
document.getElementById("EbookToolbar").style.visibility = "visible";

// Load the Ebook content into the Ebook Reader Pannel

var EbookContent = LoadFromDisk(SystemPath + EbookName);

document.getElementById("EbookCanvas").innerHTML = EbookContent;

function LoadFromDisk(filePath)
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
if (!file.exists())
var inputStream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
inputStream.init(file, 0x01, 00004, null);
var sInputStream = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream);
//alert("Exception while attempting to load\n\n" + e);

<body onLoad="Init();">

<div id="FileManager" style="position: absolute; top: 0px; left: 0px; visibility: visible;">
The eBook Library's List of Books will be listed here.
Click on one to open it in the eBook Reader
<div id="EbookCanvas" style="position: absolute; top: 0px; left: 0px; visibility: hidden;">

<div id="EbookToolbar" style="position: absolute; top: 100px; left: 0px;">
<input type="button" value="Open" OnClick="Init();">
<input type="button" value="Update" OnClick="UpdateEbookList();">
<input type="button" value="Exit" OnClick="MainMenu();">


Jan 1st, 2010, 10:57 PM
Does EbookListArray[x] contain a single quote character?

Jan 2nd, 2010, 11:58 AM
Does EbookListArray[x] contain a single quote character?

No. Just ASCII characters and a period, and a comma. As it's a CSV file.

any suggestions?