I am using an according script that requires two elements to share the same index number, for example: runAccordion2 and Accordion2Content, which both need to share the “2.”
I am dynamically populating each of those elements from a database, and using item[‘id’] to fill in the index number of each element so they are paired correctly, with each pair sharing the database index number. Unfortunately, the JS doesn’t seem to recognize the index numbering this way.
Here is the code that grabs the data from the database and shows it:
function showRecords() {
results.innerHTML = ''; // clear the results div
db.transaction(function(tx) {
tx.executeSql(selectAllStatement, [], function(tx, result) {
dataset = result.rows;
for (var i = 0, item = null; i < dataset.length; i++) {
item = dataset.item(i);
results.innerHTML = '<div id="AccordionContainer" class="AccordionContainer">';
results.innerHTML +=
'<div onclick="runAccordion(' + item['id'] + ');"><input class="AccordionTitle" type="button" value="' + item['term'] + '"></div><div id="Accordion' + item['id'] + 'Content" class="AccordionContent"><div class="glossaryContent"><button class="glossaryEditButton" style="float:left;" onClick="loadRecord(' + item['id'] + ')">Edit</button> ' + '<button class="glossaryDelButton" style="float:right;" onClick="deleteRecord(' + item['id'] + ')">Delete</button>' + item['definition'] + '</div></div>';
}
});
}); results.innerHTML += '</div>'; exportRecords(); /* populates the hidden span with non-HTML version of code so it's ready to export. */
}
Here’s the code that references the index number in the JS:
function runAccordion(index)
{
var nID = "Accordion" + index + "Content";
if(openAccordion == nID)
nID = '';
setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'"
+ openAccordion + "','" + nID + "')", 33);
openAccordion = nID;
}
As a result, when I click on the Delete or Edit buttons, they don’t active, with Google Tools stating that the index is out of bounds. Google Tools shows all the data correctly entered into the database, so the database entry part is working fine. Also, only the first record is showing; subsequent records don’t get listed.
The accordion idea is an addition to the code, which worked perfectly before adding the accordion. I am using this accordion script: http://tech.pro/tutorial/697/javascript-and-css-tutorial-accordion-menus
Thanks!