QUESTION REFERENCE TO FACILITATE THE EXAMPLE
I have the following inputs in an HTML (I will show 3, but the actual situation is 20):
<tr>
<td>Digite o código:</td>
<td><input type = "text" id="cod_item" name = "cod_item" size = 10 maxlength =5 placeholder="Código" onChange="getPeca();">
<input type = "text" id="desc_item_1" name = "desc_item_1" size = 30 maxlength =30 placeholder="Descrição">
<input type = "text" id="qtde_item_1" name = "qtde_item_1" size = 5 maxlength =5 placeholder="Qtde"></td>
</tr>
<tr>
<td>Digite o código:</td>
<td><input type = "text" id="cod_item_2" name = "cod_item_2" size = 10 maxlength =5 placeholder="Código">
<input type = "text" id="desc_item_2" name = "desc_item_2" size = 30 maxlength =30 placeholder="Descrição">
<input type = "text" id="qtde_item_2" name = "qtde_item_2" size = 5 maxlength =5 placeholder="Qtde"></td>
</tr>
<tr>
<td>Digite o código:</td>
<td><input type = "text" id="cod_item_3" name = "cod_item_3" size = 10 maxlength =5 placeholder="Código">
<input type = "text" id="desc_item_2" name = "desc_item_2" size = 30 maxlength =30 placeholder="Descrição">
<input type = "text" id="qtde_item_2" name = "qtde_item_2" size = 5 maxlength =5 placeholder="Qtde"></td>
</tr>
The intent is for all of these cod_item to access the query below and display the description in the desc_item field. Example: The user types the code and Ajax returns the description. Go to field 2 type the code and the description appears. The user can enter from 1 to 20.
$sqlRetorno = 'SELECT descricao from pecas WHERE
cod_peccin = :codItem;';
$resRetorno = $conexao->prepare($sqlRetorno);
$resRetorno->execute(array(
':codItem' => $codItem,
));
$retornos = $resRetorno->fetchAll();
In the initial question I have an Ajax but it only works for one item. In this case, how could you make all the fields do the same query and return the description of the entered item independently, without having to make a script for each field?