title: Saving a cookie for darkmode/lightmode JS - Issues
body: <p>I am trying to make the cookie load when the body does, and then check what value it is. If darkmode = true, then it should display css/cssmain.css. If it is false, it should display css/csslight.css. The cookie works: If I use the button to switch from dark to light, it changes darkmode from true (dark) to light (false) and vice-versa. It even stays when I refresh the page, but the css switches to its default file.</p>
  <p>Basically, I can not figure out how to make darkMode go into the if statement in my javascript. I tried it with onload=&quot;getCookie(darkMode)&quot; to try and put the cookie darkMode's value (true or false) into the script. It seems to just not run the script, because even if I add an alert, the alert does not pop up when I use the button.</p>
  <p>HTML:</p>
  <pre><code>&lt;head&gt;
      &lt;title&gt;Freshwater Fish&lt;/title&gt;
      &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
      &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;css/cssmain.css&quot;&gt;
      &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;css/desktopview.css&quot;&gt;
      &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;css/mobile.css&quot;&gt;
      &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;css/slides.css&quot;&gt;
      &lt;link id='css_theme' rel='stylesheet' type='text/css' href='css/csslight.css'&gt;
      &lt;script src=&quot;js/fullstackfrog.js&quot;&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body onload=&quot;getCookie(darkMode)&quot;&gt;
  
  &lt;button  class=&quot;lightmodeButton&quot; onclick=&quot;document.getElementById('css_theme').setAttribute('href', document.getElementById('theme').value, document.cookie = 'darkMode=true'); if (document.getElementById('theme').value == 'css/cssmain.css'){  document.getElementById('theme').value = 'css/csslight.css'; document.cookie = 'darkMode=true';} else{ document.getElementById('theme').value = 'css/cssmain.css'; document.cookie = 'darkMode=false';}&quot;&gt;Light/Dark&lt;/button&gt;
  &lt;input type=&quot;hidden&quot; id=&quot;theme&quot; value=&quot;css/cssmain.css&quot;&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>JS (fullstackfrog.js):</p>
  <pre><code>function getCookie(name) {
    if (name) {
      document.getElementById('theme').value = 'css/cssmain.css';
    }
    else {
      document.getElementById('theme').value = 'css/csslight.css';
    }
  }
  </code></pre>
  <pre><code></code></pre>