title: Can I call a function () in a Document.write()?
body: <p>I am trying to make sure my aplication is DRY (Don't repeat yourself) by having my navbar in a javascript file by using the DOM Write to write my html code to the html page. but the problem it's not executing the function call. </p>
  
  <p>I have tried using single quotation marks around the function call as shown in my code.</p>
  
  <p><strong>Navbar.js</strong></p>
  
  <pre><code> document.write("&lt;div class='w3-bar w3-light-grey'&gt;"+ "&lt;a href='#' class='w3-bar-item w3-button'&gt;Home&lt;/a&gt;"+"&lt;div class='w3-dropdown-hover'&gt;"+"&lt;button class='w3-button'&gt;Cities&lt;/button&gt;"+"&lt;div class='w3-dropdown-content w3-bar-block w3-card-4'&gt;"+"&lt;a href='#' class='w3-bar-item w3-button' onclick='myFunction('Auckland')'&gt;Auckland&lt;/a&gt;"+
  "&lt;a href='#' class='w3-bar-item w3-button' onclick='myFunction('Christchurch')'&gt;Christchurch&lt;/a&gt;"+"&lt;a href='#' class='w3-bar-item w3-button' onclick='myFunction('Hamilton')'&gt;Hamilton&lt;/a&gt;"+ "&lt;/div&gt;"+"&lt;/div&gt;"+ "&lt;/div&gt;");
  </code></pre>
  
  <p><strong>Cities.html</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
   &lt;html&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
      &lt;link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"&gt;
      &lt;body&gt;
           &lt;script scr="includes/Navbar.js"&gt;&lt;/script&gt;
           &lt;script&gt;
                 function myFunction(id) {
                    if(id == 'Auckland'){
                        document.write("&lt;h1&gt;Auckland&lt;/h1&gt;");
                    }else if(id == 'Auckland'){
                        document.write("&lt;h1&gt;Christchurch&lt;/h1&gt;");
                    }else {
                        document.write("&lt;h1&gt;Hamilton&lt;/h1&gt;");
                    }
                  }
            &lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>
  
  <p>When i click on one of the dropdown list item the function will take the passed in text and try to match it with the id and then using DOM to write the name of a city in h1 tages. (creating content on the html page)</p>