title: Dynamically Created Input (type=“file”) and Form Elements
body: <p>As slowly devloping my app because I am still learning I ran into another problem.</p>
  
  <p>I generated with JS a form, a file input and a submit input in order to upload some photos and to display their thumnails with a .php file. I have this code. I mention that this is a part of a cascade menu.</p>
  
  <p>When I try to upload the photos I get this error: "Uncaught TypeError: Cannot set property 'value' of null " in .php file.</p>
  
  <p>I also want to mention that the same php script works fine if the HTML elements are not generated and they are witten in pure HTML.</p>
  
  <p>I know this php script is not complete but this is only for testing purposes.</p>
  
  <p>JS</p>
  
  <pre><code>var form = document.createElement("FORM");
      second_plate.appendChild(form);
      form.setAttribute("id" , "form");
      form.setAttribute("action" , "upload.php");
      form.setAttribute("method" , "post");
      form.setAttribute("enctype" , "multipart/form-data");
      form.setAttribute("target" , "iframe");
      console.log(form);
  
      var inputpic = document.createElement("INPUT");
      form.appendChild(inputpic);
      inputpic.setAttribute("type" , "file");
      inputpic.setAttribute("name" , "file");
      inputpic.setAttribute("id" , "file");
  
  
      var submitpic = document.createElement("INPUT");
      form.appendChild(submitpic);
      submitpic.setAttribute("id" , "submit");
      submitpic.setAttribute("name" , "submit");
      submitpic.setAttribute("type" , "submit");
      submitpic.setAttribute("value" , "Upload photo");
  
      var photosplace = document.createElement("DIV");
      second_plate.appendChild(photosplace);
      photosplace.setAttribute("id" , "photos");
  
      var iframe = document.createElement("IFRAME");
      second_plate.appendChild(iframe);
      iframe.setAttribute("id" , "iframe");   
      iframe.setAttribute("name" , "iframe");
      iframe.style.width = "0%";  
      iframe.style.height = "0%"; 
      iframe.style.display = "none";  
  </code></pre>
  
  <p>PHP</p>
  
  <pre><code>&lt;?php
  
          if ($_FILES['file']['size'] &gt; 0) {
  
              if (move_uploaded_file($_FILES['file']['tmp_name'], uploads/".$_FILES['file']"name"])) {
  
                  ?&gt;
                  &lt;script&gt;
                      document.getElementById("file").value = "";
                      updatepic("&lt;?php echo 'uploads/'.$_FILES['file']["name"]; ?&gt;");             
                  &lt;/script&gt;
                  &lt;?php
              }
          }
  
  
  ?&gt;
  </code></pre>