title: sending textbox contect to php via js, processing the value and getting a new value back to html page
body: <p>Im trying to process on PHP, HTML input from the user, i want as the user types, on event of onkeyup send it to php and get a value back and post it back to the html.
  the problem is that i cant find a way to do it without submitting the form, any advise?
  Thank you!</p>
  
  <p>my HTML:</p>
  
  <pre><code>&lt;input id="userin" type="text" name="myinput" onkeyup="valfunction()"&lt;br&gt;
  &lt;p id="myresult"&gt;value after php processing.&lt;/p&gt;
  </code></pre>
  
  <p>my JS:</p>
  
  <pre><code>function valfunction() {
      var xhttp = new XMLHttpRequest();
  
          xhttp.onreadystatechange = function () {
              if (this.readyState == 4 &amp;&amp; this.status == 200) {
                  document.getElementById("myresult").innerHTML = 
                  this.responseText;
              }
          };
      xhttp.open("GET", "newval.php", true);
      xhttp.send();
  }
  </code></pre>
  
  <p></p>
  
  <p>My PHP:</p>
  
  <pre><code>&lt;?php
      $text=$_POST['mytext'];
          if ($text=='a') $a=1;
          else if ($text=='b') $a=2;
          else if ($text=='c') $a=3;
  echo $a;
  ?&gt;
  </code></pre>