title: Sending file from html form to php through javascript
body: <p>I have created a form in javascript. I don't want to have a submit button on this because it is just one input field. To make it without I just used the onchange function. So my form looks like the following...</p>
  
  <pre><code>&lt;form method="post" name="uploadImage"&gt;
  &lt;input type="file" id="uploadImg" name="uploadImg" onchange="fileClick()" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Then to account make the form submit I used the js submit function. So my Javascript is the following.  </p>
  
  <pre><code>function fileClick(){
  
  document.forms["uploadImage"].submit();
  
  $.post(
  "uploadImage.php",
  {image : $("#uploadImg").val()},
  function(data, status){
  alert(data);
  $("#uploadedImgs").innerHTML = "&lt;img src='" + data + "' alt='uploadedImg' /&gt;";
  });
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>(and yes I have correctly included JQuery)
  But then when I try to submit my data into the php file using this I keep getting it saying $_FILES['image'] is null. My php code is below.</p>
  
  <pre><code>&lt;?php
  if($_FILES['image']){
  echo "Image set";
  } else {
  echo "No image selected";
  }
  ?&gt;
  </code></pre>
  
  <p>Any help is greatly appreciated. Also if you have a simpler way of doing what I'm trying to do all suggestions are accepted. Thank you all for your help. :D</p>
  
  <p>(final note after post) Yes I am aware that there are also questions very similar to this but most of them are way more advanced than I am with Javascript. This being as simple as it is was very hard and time consuming for me to figure out how to get it to work. So please don't mark as duplicate because I can't understand the other peoples answers. SORRY :(</p>