Fill a field by selecting another field

Asked

Viewed 374 times

0

I have an order form where the name of the customer is chosen and I would like from this selection to be filled in the discount field, this value is in the same table where the customer registration is.

How can I make the discount field be filled from the customer’s choice?

my select is like this:

    $qr2=mysqli_query($conexao,"SELECT * FROM `clientes` order by `nome`");
if (mysqli_num_rows($qr2)==0)
    echo "Adicione ao menos um Cliente";

the field in the form where the customer is chosen is thus:

    <strong><b><font size="3"> <font color="#000000">Cliente :</strong>
<select name="clienteAt">  <option value="">Selecione o Cliente</option>
<?php
while ($row=mysqli_fetch_array($qr2)){
?>
<option value="<?php echo $row['id']?>"><?php echo $row['nome']?></option>
<?php }?>
</select>

and the discount field is like this:

<td>
 <input name="desconto[]" type="text" required name="desconto"
  maxlength="30" size="11" onblur="Calc(this)"
  style="text-align:center"
  class="desconto" />
</td>
  • Use javascript.

  • You can store client discount data in a js array and use logic to set the value in the input

1 answer

1

I’ll try to give more or less the idea of what you can do.

1 - When selecting a client in your combobox create an ajax request for another page ex: getDescontoClient.php with the id of the selected client.

2- On the getDescontoCliente.php page get the id through a $_GET and make your discount selection in your database.

3 - Give an ECHO at the discount value on the same page.

4 - take the return of the ajax request made on the combobox page and fill in the input with this return.

I passed but the idea of what you can do.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.