传递文本框的值以在另一个文本框上生成查询

How to post the value of input sub to function my query in the next input without reloading the page?

I need to post the value to process my query. How to do this?

Help please

<input name="sub" id="sub" value="" style="width:35px;text-transform:uppercase;">

<input id="sub1" name="sub1" style="width:35px;text-transform:uppercase;" 
value='<?php

$sub=$_POST['sub'];

$mysqli = new mysqli("localhost", "root", "", "2015");
$result2 = $mysqli->query("SELECT * FROM code
WHERE sub1code LIKE '$sub-___' ORDER BY sub1code");

while($row = $result2->fetch_assoc())
  {
  $value = $row['sub1code'];
  }
  $first = substr($value, 0, 4);
  echo $first;
  $last = substr($value, -3);
  $i="0";
  while($i<=$last)
  {
  $i++;
  }
  $value2=strlen($i);
    echo $first;
    if($value2==1)
    {
    echo "00".$i;
    }
    elseif($value2==2)
    {
    echo "0".$i;
    }
    else
    {
    echo $i;
    }
?>'>

You need to separate the code that generates the value for the second input into a different file. Then you use Javascript to start an AJAX call after the user entered the value for input1 to retrieve the value for input2.