if else语句将数据从输入的数字插入到文本框中

If user enter 50 at the quantity textbox, and must show "Do load into 3 ton lorry" in the type of lorry textbox and vice versa

<tr>
    <th>
        <center>Quantity:</center>
    </th>
    <td>
        <input type="text" name="quantity" />
    </td>
</tr>
<tr>
    <th>
        <center>Type of Lorry:</center>
    </th>
    <td>
        <input type="text" name="barcode" />
    </td>
    <?php
        if ($quantity > 40) echo "Do load into 3 ton lorry";
        else echo "Do load into 1 ton lorry";
    ?>
</tr>

PHP is server-side. Therefore, you should use javascript to response as you enter a number without reloading the page. For a solution, refer to https://www.w3schools.com/jsref/event_onkeypress.asp

You should try this:

<script>
   function search(ele) {
       if(event.key === 'Enter')
       {
           if(ele.value > 40) {
               document.getElementById("barcode").value = "Do load into 3 ton lorry";
           }

           else {
               document.getElementById("barcode").value = "Do load into 1 ton lorry";
           }
       }
   }
</script>
<table>
<tr>
<th><center>Quantity:</center></th>
<td> <input type="text" name="quantity" onkeydown="search(this)" /></td>
</tr>
<tr>
<th><center>Type of Lorry:</center></th>
<td> <input type="text" name="barcode" id="barcode" /></td>

</tr>
</table>