title: How to Check if the the user has uploaded a file or not in Javascript
body: <p>I have created a form in which I have 2 text fields and one File field. I have added Javascript on <code>'text'</code> fields. If user left <code>'text'</code> fields and press submit button, <code>All Fields are Required</code>Font turns red, I want to turn it red as well when user doesn't upload any Image. I have tried various ways but its not working. Kindly tell me the way of doing it.</p>
  
  <pre><code>      &lt;script type="text/javascript"&gt;
  
  function myFunction()
  {
      var category_name   =   document.forms["insert"]["sub_category_name"].value;
      //var image =           document.forms["insert"]["file"].item();
  
      var error           =   document.getElementById("error");
  
  
      if(category_name=="" )
      {
          error.style.color="Red";
          return false;
          }
          else
          {
              //message.innerHTML="Data Inserted!";
              }
      }
  
  
  &lt;/script&gt;
  </code></pre>
  
  <p>PHP code</p>
  
  <pre><code>    &lt;?php
  
  echo "
      &lt;form name='insert' action='sub_categories.php' method='POST' onSubmit='return myFunction()' enctype='multipart/form-data'&gt;
          &lt;table class='gridtable' border=2 bordercolor='#CCCCCC' cellpadding='10'&gt;
          &lt;tr&gt;
          &lt;th&gt;
              Sub-Category Name: &lt;/th&gt;&lt;td&gt;    &lt;input type='text' name='sub_category_name' &gt;&lt;/td&gt;&lt;/tr&gt;";
  
  
  
  
  
              echo "
          &lt;tr&gt;
          &lt;th&gt;
              Image1:&lt;/th&gt;&lt;td&gt; &lt;input type='file' name= 'file' &gt;&lt;/td&gt;&lt;/tr&gt; 
  
              ";
  </code></pre>
  
  <p>Thanks </p>