title: Javascript check 'URL' is empty then populate with "" , else display url as hyperlink
body: <p>I have some Javascript that displays titles from an XML.</p>
  
  <p>When the title is clicked the information associated with it will pop up. I am having trouble when URL is empty.
  If it is empty I don't want the URL displayed. It should just look like URL.</p>
  
  <p>If it is present I want the url displayed as a hyperlink.</p>
  
  <p>I am new to this so please take it easy on me!</p>
  
  <p>XML</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;notepad&gt;
    &lt;nextID&gt;114&lt;/nextID&gt;
    &lt;memos&gt;
      &lt;memo id="100"&gt;
        &lt;title&gt;Valentines&lt;/title&gt;
        &lt;sender&gt;James Mcavoy&lt;/sender&gt;
        &lt;recipient&gt;Clara Croft&lt;/recipient&gt;
        &lt;date&gt;11/09/17&lt;/date&gt;
        &lt;message&gt;Let me know what you would like for Valentines&lt;/message&gt;
        &lt;url&gt;www.heresyourpresent.com&lt;/url&gt;
      &lt;/memo&gt;
      &lt;memo id="101"&gt;
        &lt;title&gt;Birthday&lt;/title&gt;
        &lt;sender&gt;Louise King&lt;/sender&gt;
        &lt;recipient&gt;Lily May&lt;/recipient&gt;
        &lt;date&gt;13/10/17&lt;/date&gt;
        &lt;message&gt;I will be there for your birthday! What cake would you like?&lt;/message&gt;
        &lt;url&gt;www.findmycake.com&lt;/url&gt;
      &lt;/memo&gt;
      &lt;memo id="102"&gt;
        &lt;title&gt;Christmas&lt;/title&gt;
        &lt;sender&gt;Monty Python&lt;/sender&gt;
        &lt;recipient&gt;Jack Maloe&lt;/recipient&gt;
        &lt;date&gt;16/11/17&lt;/date&gt;
        &lt;message&gt;What would you like for Chrismtas Jack ?&lt;/message&gt;
        &lt;url&gt;www.socksrus.co.uk&lt;/url&gt;
      &lt;/memo&gt;
      &lt;memo id="103"&gt;
        &lt;title&gt;Easter&lt;/title&gt;
        &lt;sender&gt;Carolyn Lynemouth&lt;/sender&gt;
        &lt;recipient&gt;Mercedes Hugh&lt;/recipient&gt;
        &lt;date&gt;30/04/17&lt;/date&gt;
        &lt;message&gt;I got a few easter eggs for your daughter on this site, is this ok?&lt;/message&gt;
        &lt;url&gt;www.eastereggs.com&lt;/url&gt;
      &lt;/memo&gt;
      &lt;memo id="104"&gt;
        &lt;title&gt;Christening&lt;/title&gt;
        &lt;sender&gt;Dylan Bramble&lt;/sender&gt;
        &lt;recipient&gt;Kelly Love&lt;/recipient&gt;
        &lt;date&gt;07/05/17&lt;/date&gt;
        &lt;message&gt;I have sent you an e-voucher for a baby store&lt;/message&gt;
        &lt;url&gt;www.firstchristening.com&lt;/url&gt;
      &lt;/memo&gt;
      &lt;memo id="105"&gt;
        &lt;title&gt;Wedding&lt;/title&gt;
        &lt;sender&gt;Polly Wisener&lt;/sender&gt;
        &lt;recipient&gt;Natasha Kirkpatrick&lt;/recipient&gt;
        &lt;date&gt;12/06/18&lt;/date&gt;
        &lt;message&gt;Remember to go to attend the dress fitting please on Friday&lt;/message&gt;
        &lt;url&gt;dgdfgdffg&lt;/url&gt;
      &lt;/memo&gt;
      &lt;memo id="106"&gt;
        &lt;title&gt;Graduation&lt;/title&gt;
        &lt;sender&gt;Kathryn Kirke&lt;/sender&gt;
        &lt;recipient&gt;Cara Lovejoy&lt;/recipient&gt;
        &lt;date&gt;04/07/18&lt;/date&gt;
        &lt;message&gt;Just to let you know I can't make your graduation, sorry&lt;/message&gt;
        &lt;url&gt;www.makegraduationspecial.co.uk&lt;/url&gt;
      &lt;/memo&gt;
      &lt;memo id="107"&gt;
        &lt;title&gt;Anniversary&lt;/title&gt;
        &lt;sender&gt;Eric Simpleton&lt;/sender&gt;
        &lt;recipient&gt;Grainne Simpleton&lt;/recipient&gt;
        &lt;date&gt;18/08/17&lt;/date&gt;
        &lt;message&gt;Be at le maison restaurant at 7pm this Thursday. I have a table booked&lt;/message&gt;
        &lt;url&gt;dfgdfgdfgfd&lt;/url&gt;
      &lt;/memo&gt;
      &lt;memo id="108"&gt;
        &lt;title&gt;Baby Shower&lt;/title&gt;
        &lt;sender&gt;Hyacinth Bouquet&lt;/sender&gt;
        &lt;recipient&gt;Gemma Hamilton&lt;/recipient&gt;
        &lt;date&gt;20/12/17&lt;/date&gt;
        &lt;message&gt;I will attend your baby shower&lt;/message&gt;
        &lt;url&gt;www.babygift.co.uk&lt;/url&gt;
      &lt;/memo&gt;
      &lt;memo id="109"&gt;
        &lt;title&gt;Stag&lt;/title&gt;
        &lt;sender&gt;John Smith&lt;/sender&gt;
        &lt;recipient&gt;Cara Lovejoy&lt;/recipient&gt;
        &lt;date&gt;22/12/17&lt;/date&gt;
        &lt;message&gt;Your stag do will be in Marbella. I have your tickets&lt;/message&gt;
        &lt;url&gt;www.thelaststag.co.uk&lt;/url&gt;
      &lt;/memo&gt;
      &lt;memo id="110"&gt;
        &lt;title&gt;New Home&lt;/title&gt;
        &lt;sender&gt;Opal Newfridge&lt;/sender&gt;
        &lt;recipient&gt;Kylie Jenner&lt;/recipient&gt;
        &lt;date&gt;19/07/17&lt;/date&gt;
        &lt;message&gt;Congratulations on the new home. Can't wait for a cuppa&lt;/message&gt;
        &lt;url&gt;www.newhomesforyou.com&lt;/url&gt;
      &lt;/memo&gt;
      &lt;memo id="111"&gt;
        &lt;title&gt;Communion&lt;/title&gt;
        &lt;sender&gt;John Smith&lt;/sender&gt;
        &lt;recipient&gt;Hilary Clinton, Jacob Marks, Lilly Popper&lt;/recipient&gt;
        &lt;date&gt;22/12/17&lt;/date&gt;
        &lt;message&gt;Your stag do will be in Marbella. I have your tickets&lt;/message&gt;
        &lt;url&gt;www.thelaststag.co.uk&lt;/url&gt;
      &lt;/memo&gt;
      &lt;memo id="112"&gt;
        &lt;title&gt;Retirement Party&lt;/title&gt;
        &lt;sender&gt;Kylie Jenner&lt;/sender&gt;
        &lt;recipient&gt;Chloe Jenner, Rob Stark, Patrick Hunter, Julie Smith, Helen Doe&lt;/recipient&gt;
        &lt;date&gt;22/07/17&lt;/date&gt;
        &lt;message&gt;Please join us at Lodge Hotel for Robs Retirement Dinner&lt;/message&gt;
        &lt;url&gt;www.lodge.com&lt;/url&gt;
      &lt;/memo&gt;
       &lt;memo id="113"&gt;
        &lt;title&gt;Fathers Day&lt;/title&gt;
        &lt;sender&gt;Carolyn Lynemouth&lt;/sender&gt;
        &lt;recipient&gt;Rob Stark&lt;/recipient&gt;
        &lt;date&gt;22/07/17&lt;/date&gt;
        &lt;message&gt;We will be sending you away for the weekend to London!&lt;/message&gt;
        &lt;url&gt;www.easyflights.com&lt;/url&gt;
      &lt;/memo&gt;
    &lt;/memos&gt;
  &lt;/notepad&gt;
  </code></pre>
  
  <p>Code is below</p>
  
  <pre><code>xmlhttp = new XMLHttpRequest();
  xmlhttp.open("GET", "memos.xml", false);
  xmlhttp.send();
  xmlDocument = xmlhttp.responseXML;
  memos = xmlDocument.getElementsByTagName("memo");
  
  table = "&lt;tr&gt;&lt;th&gt;Title&lt;/th&gt;&lt;/tr&gt;";
  for (count = 0; count &lt; memos.length; count++) {
    table += "&lt;tr onclick='displayTitle(" + count + ")'&gt;&lt;td&gt;";
    table += memos[count].getElementsByTagName("title")[0].childNodes[0].nodeValue;
    table += "&lt;/td&gt;";
  }
  document.getElementById("demo").innerHTML = table;
  
  function displayTitle(count) {
  
    document.getElementById("showTitle").innerHTML =
      "ID: " +
      memos[count].getAttribute("id") +
      "&lt;br&gt;Title: " +
      memos[count].getElementsByTagName("title")[0].childNodes[0].nodeValue +
      "&lt;br&gt;Sender: " +
      memos[count].getElementsByTagName("sender")[0].childNodes[0].nodeValue +
      "&lt;br&gt;Recipient: " +
      memos[count].getElementsByTagName("recipient")[0].childNodes[0].nodeValue +
      "&lt;br&gt;Date: " +
      memos[count].getElementsByTagName("date")[0].childNodes[0].nodeValue +
      "&lt;br&gt;Message: " +
      memos[count].getElementsByTagName("message")[0].childNodes[0].nodeValue +
      "&lt;br&gt;Url: " +
      urlNode = memos[count].getElementsByTagName("url")[0];
    if (urlNode.hasChildNodes()) {
      url = urlNode.childNodes[0].nodeValue;
    } else {
      url = "";
    }
  
  }
  </code></pre>