title: If statement when checkbox is checked?
body: <p>A little question here, I'm trying to execute a huge calculation that will determine something randomly within a value range. I want the user to determine this range himself, and let him choose wether he wants to add a maximum value or a minimum value. Basically, everything works for now, but I'm trying to put an "if" statement at the beginning to check if the checkboxes are checked or not in order to prompt the proper questions. The problem is, the way I'm writing it right now makes it impossible to read the program: it simply does nothing. The error message displayed is: <br></p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot read property 'checked' of null(…). <br></p>
  </blockquote>
  
  <p>I tried a few things, and when I set the values myself, it works, so the problem is really the "if" statement. Here are my global vars and the part that doesnt work:</p>
  
  <pre><code>    var maxdesiredvalue, mindesiredvalue;
  
                      if (document.getElementById("min").checked == false) {
                          mindesiredvalue = 0.00
                      }
                      else {
                      mindesiredvalue = window.prompt("Valeur minimale désirée:"); 
                      mindesiredvalue = parseInt(mindesiredvalue)}
  
                      if (document.getElementById("max").checked == false) {
                          maxdesiredvalue = 9999999.99
                      }
                      else {
                      maxdesiredvalue = window.prompt("Valeur maximale désirée:");
                      maxdesiredvalue = parseInt(maxdesiredvalue)}
  
          function RandWeap() {
               /*Huge function here determining a value and repeating until it 
               is between mindesiredvalue and maxdesiredvalue*/
          }
  </code></pre>
  
  <p>The checkboxes are written like this:</p>
  
  <pre><code>&lt;body&gt;
      &lt;form&gt;
      &lt;i&gt; Press F5 to clear or to get 1 random weapon &lt;/i&gt; &lt;br&gt; &lt;br&gt;
      Min price: &lt;input type="checkbox" id="min"&gt; &lt;br&gt;
      Max price: &lt;input type="checkbox" id="max"&gt; &lt;br&gt; &lt;br&gt;
      &lt;button type="button" onclick="RandWeap()"&gt;Add a random weapon to list&lt;/button&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>Any idea of how to get it working?</p>
  
  <p>Thank you!</p>
  
  <p><strong>EDIT</strong> <br> <br>
  Alright, so basically if we can give an exemple of something similar but really simplified,it would look like this:</p>
  
  <pre><code>&lt;html&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;script type="text/javascript" language="JavaScript"&gt;
  
  var desiredResult;
  
  desiredResult = (parseInt(window.prompt("Valeur désirée")))
  
      function dice(){
  
      var result, missed;
  
      result = (Math.floor(Math.random() * 6) + 1)
  
      if (desiredResult == result) {document.body.innerHTML += result}
      else if (desiredResult != result) {dice()}
  
      }
  
  window.onload = dice
  
  &lt;/script&gt;
  &lt;body&gt;
      Choose value: &lt;input type="checkbox" id="choose"&gt; &lt;br&gt; &lt;br&gt;
      &lt;button type="button" onclick="dice()"&gt;Roll dice!&lt;/button&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>So we prompt a desired value, and then repeat the function until it is our desired value. Now, what should be the edits to this code in order to have it prompt the desired value ONLY if a checkbox is checke?. So, onload, of course, it would not be checked, so it would only enter the random value. Then, when we click a button, it repeats this step, but if we checked the box just before, it will prompt the desired value. I'm not sure if it's clear... but basically that's what I want to know. If anyone has any idea of the code I need to add, would be very nice!</p>