title: Open a materialize modal not working with if codition
body: <p>I want to open a modal window when some conditions are met. I looked for some code and tried to implement it however, it does not work for me.</p>
  
  <p>I have a If condition also in place could that be the reason?</p>
  
  <p>Complete JS code: </p>
  
  <pre><code>  &lt;script&gt;
    document.addEventListener('DOMContentLoaded', function() {
      var elems = document.querySelectorAll('select');
      var instances = M.FormSelect.init(elems);
    });
  
    document.getElementById('btn').addEventListener('click',dostuff);
  
  
  function dostuff() {
      var userinfo = {};
  
      userinfo.firstname = document.getElementById('nm').value;
      userinfo.email = document.getElementById('mail').value;
      userinfo.process = document.getElementById('process').value;
  
      if (userinfo.firstname == "" || userinfo.email == "" || userinfo.process == "Choose your option"){
  
          alert("Hello, \n\nAll Fields are required.\n\nPlease Select all the Fields.");
  
      } else {       
          google.script.run.userClicked(userinfo);
  
          document.getElementById('nm').value = "";
          document.getElementById('mail').value = "";
          var selc = document.getElementById('process')
          selc.selectedIndex = 0;
          M.FormSelect.init(selc);
  
          document.addEventListener('DOMContentLoaded', function () {
              var Modalelem = document.querySelector('.modal');
              var instance = M.Modal.init(Modalelem);
              instance.open();                         
          });
      }        
  } 
  </code></pre>
  
  <p>Please focus on the below mentioned code as this is my real concern:-</p>
  
  <pre><code>document.addEventListener('DOMContentLoaded', function () {
              var Modalelem = document.querySelector('.modal');
              var instance = M.Modal.init(Modalelem);
              instance.open();
  </code></pre>