title: Javascript variable change with onclick
body: <p>I want to have a variable changed within a checkbox that causes an if statement to compute without reloading the page, but I'm struggling... still learning, sorry!</p>
  
  <p>Here's the relevant code:</p>
  
  <pre><code> &lt;!--Variable declaration--&gt;
   &lt;script type="text/javascript"&gt; var lettuce = false; &lt;/script&gt;
  
   &lt;!--The following line is within a form--&gt;
   &lt;input type="checkbox" onclick="lettuce=true" name="food" value="lettuce" /&gt; Lettuce&lt;br /&gt;
  
   &lt;--the if statement--&gt;
   &lt;script type="text/javascript"&gt;    
        if (lettuce == true) {
      document.write("45");   
    }
   &lt;/script&gt;
  </code></pre>
  
  <p>Thanks!</p>