title: Activate HTML5 required validation with javascript and get result
body: <p>I've searched for a solution for hours but I can't find anything helpful in my case...</p>
  
  <p>So, I have a form with an id, inputs within the form with required attribute. I also have a javascript function that send the form data to the PHP server through AJAX.</p>
  
  <p>What I want is: when I click on my validation button, the JS function launches and check if the form is filled correctly (like it does with a normal submit). If it's not I'd like the required input message to show up, and my function to stop. If it is, I'd like my function to continue.</p>
  
  <p>Here's a simplified version of my HTML code:</p>
  
  <pre><code>&lt;form id="myform"&gt;
     &lt;input type="text" id="myinput" required /&gt;
     &lt;img src="img/some_img.png" onClick="do_js();" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And the Javascript code:</p>
  
  <pre><code>function do_js()
  {
     /* getting my form */
     var myform = document.getElementById('myform');
  
     /* HERE I want to check if my form is correctly filled */
     /* but not with a custom validation, I want the HTML5 required stuff to activate */
     /* then IF my form is okay, i want to send data through ajax */
  
     /* getting my data */
     var some_value = document.getElementById('myinput').value;
  
     /* sending my data */
     xhr.open('POST', 'ajax_page.php', true);
     xhr.onreadystatechange = function() { /* result stuff */ };
     xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
     xhr.send('myvalue='+some_value);
  }
  </code></pre>
  
  <p>I'm working in PLAIN JAVASCRIPT (not with jQuery).</p>