title: Calling a function without clicking anything
body: <p>I'm new in programming and I'm trying to call a function without any button or click event. I'm doing a table within a table using javascript function. Here's my code so far: <br><br></p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt; &lt;title&gt; Hello &lt;/title&gt; &lt;/head&gt;
  &lt;body&gt;
  &lt;table border=1&gt;
      &lt;tr&gt;
          &lt;td&gt; Hello! &lt;input type='hidden' value='0' id='theValue' /&gt; &lt;script&gt; add(); &lt;/script&gt; &lt;div id='myDiv'&gt; &lt;/div&gt; &lt;/td&gt;
      &lt;/tr&gt;
  
  &lt;script&gt;
  $ctra = 1;
  $ctr1a = 1;  
  function add() { 
      var ni = document.getElementById('myDiv');
      var numi = document.getElementById('theValue');
      var num = (document.getElementById('theValue').value -1)+ 2;
      numi.value = num;
      var newdiv = document.createElement('div');
      var divIdName = 'my'+num+'Div';
      newdiv.setAttribute('id',divIdName);
      newdiv.innerHTML = "&lt;table border=1&gt;"+
                          "&lt;tr&gt;"+
                          "&lt;td&gt; Hello! &lt;input type='hidden' value='0' id='theValue' /&gt; &lt;script&gt; add(); &lt;/script&gt; &lt;div id=('" + divIdName + "')&gt; &lt;/div&gt; &lt;/td&gt;"+
                          "&lt;/tr&gt;"+
                          "&lt;/table&gt;";
      if($ctra&lt;100){
          ni.appendChild(newdiv);
          $ctra++;
      }
  }
  &lt;/script&gt;
  
  &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><br>
  When I run it, it displays<br></p>
  
  <pre><code>"+ ""+ "
  Hello!
  "; if($ctra&lt;100){ ni.appendChild(newdiv); $ctra++; } }
  </code></pre>
  
  <p><br>
  in the browser. What could the problem be? Thank you in advance!<br><br>
  <strong>EDIT</strong><br></p>
  
  <pre><code>function add() { 
      var ni = document.getElementById('myDiv');
      var numi = document.getElementById('theValue');
      var num = (document.getElementById('theValue').value -1)+ 2;
      numi.value = num;
      var newdiv = document.createElement('div');
      var divIdName = 'my'+num+'Div';
      newdiv.setAttribute('id',divIdName);
      newdiv.innerHTML = "&lt;table border=1&gt;&lt;tr&gt;&lt;td&gt; Hello! &lt;input type='hidden' value=0 id='theValue' /&gt;&lt;div id='" + divIdName + "'&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;";
      ni.appendChild(newdiv);
      for(var i=1;i&lt;100;i++) {
          var ni = document.getElementById(divIdName);
          var numi = document.getElementById('theValue');
          var num = (document.getElementById('theValue').value -1)+ 2;
          numi.value = num;
          var newdiv = document.createElement('div');
          var divIdName = 'my'+num+'Div';
          newdiv.setAttribute('id',divIdName);
          newdiv.innerHTML = "&lt;table border=1&gt;&lt;tr&gt;&lt;td&gt; Hello! &lt;input type='hidden' value='" + i + "' id='theValue' /&gt;&lt;div id='" + divIdName + "'&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;";
          ni.appendChild(newdiv);
      }
  }
  </code></pre>