Note that there are some explanatory texts on larger screens.

plurals
  1. POonclick event not firing
    text
    copied!<pre><code>var subjectList; function PageMaster() { this.contentDiv = document.getElementById("content"); } /** * Builds the main part of the web page based on the given XML document object * * @param {Object} xmlDoc the given XML document object */ PageMaster.prototype.doIt = function(xmlDoc) { alert("PageMaster()"); alert("Clear page..."); this.contentDiv.innerHTML = ""; if (null != xmlDoc) { alert("Build page..."); //create div Post var divPost = document.createElement("div"); divPost.className = "post"; //create h1 element var h1Element = document.createElement("h1"); var headingText = document.createTextNode("Invitations"); h1Element.appendChild(headingText); //insert h1 element into div post divPost.appendChild(h1Element); subjectList = xmlDoc.getElementsByTagName("subject"); var groupList = xmlDoc.getElementsByTagName("group"); for (var i = 0; i &lt; subjectList.length; i++) //for each subject { var divEntry = document.createElement("div"); divEntry.className = "entry"; var subjectNum = subjectList[i].attributes[0].nodeValue; var subjectName = subjectList[i].attributes[1].nodeValue; var groupId = groupList[i].attributes[0].nodeValue; var groupName = groupList[i].attributes[1].nodeValue; var ownerId = groupList[i].attributes[2].nodeValue; //set up the invitation table attributes var table = document.createElement("table"); table.width = 411; table.border = 3; table.borderColor = "#990000" tableRow = table.insertRow(0); tableCell = tableRow.insertCell(0); var cellContent = ""; //create invitation message var invitationMsg = "&lt;p&gt;Subject : " + subjectNum + " - " + subjectName + "&lt;/p&gt;"; invitationMsg += "&lt;p&gt;You are invited to join " + groupName + " (groupId : " + groupId + ") by owner Id:" + ownerId + "&lt;/p&gt;"; cellContent += invitationMsg; //create buttons cellContent += "&lt;input type='button' id='acceptButton" + i + "' value='Accept' onclick='acceptInvitation(i)'&gt;" cellContent += "&lt;input type='button' id='declineButton" + i + "' value='Decline'&gt;" tableCell.innerHTML = cellContent; divEntry.appendChild(table); var blankSpace = document.createElement("p"); divEntry.appendChild(blankSpace); divPost.appendChild(divEntry); } //insert div post into div content this.contentDiv.appendChild(divPost); } }; function acceptInvitation(i) { alert("hello"); //alert(subjectList[i].attributes[0].nodeValue); } </code></pre> <p>above is extract of my javascript code. What the code do is to create a table of inviting group from the xml file with accept and decline button. when user press accept, the table will disappear and the table below will move up. For now I am only testing my accept invitation button to see if it works.But my onclick function in the accept button does not work for some reason I don't understand. the alert in acceptInvitation() is not read. Any help will be appreciated. Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload