0

I have a javascript table that displays contents from an XML file(that stores letter details), I have at each row a view button which I would like the user to be able to click and it will display the letter details for them. Is this possible?
The javascript I have is:

function showLetter() {
   for (var i=0; i<letters.length; i++) {
      id=letters[i].getAttribute("id");
      title=letters[i].getElementsByTagName("title")[0].childNodes[0].nodeValue;
      sender=letters[i].getElementsByTagName("author")[0].childNodes[0].nodeValue;
      recipient=letters[i].getElementsByTagName("recipient")[0].childNodes[0].nodeValue'
      date=memos[i].getElementsByTagName("date")[0].childNodes[0].nodeValue;
      body=memos[i].getElementsByTagName("body")[0].childNodes[0].nodeValue;
      document.write("<tr><td class='noBox'>"+id+"</td>"+
                         "<td>"+title+"</td>"+
                         "<td class='center'>"+sender+"</td>"+
                          "<td class='center'>"+recipient+"</td>"+
                             "<td class='center'>"+date+"</td>"+
                         "<td class='center'><input type='submit' name='submit' value='remove' onClick='showItem()'></td></tr>");
   }
2
Contributors
1
Reply
7
Views
4 Years
Discussion Span
Last Post by GliderPilot
0

Easiest way is to pass the id through your function call.

<input type='submit' name='submit' value='remove' onClick='showItem(id)'>

And your function

function showItem(itemID)
{
  //You now have your item's ID so you can pull the required data based on that ID
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.