Add product value to purchase

Asked

Viewed 125 times

0

Good guys I’m with the following difficulty, I have a very simple panel for sale : inserir a descrição da imagem aqui

as you can see I have a combobox with some products in it , my problem and the following I would need as soon as I chose any of the products there , automatically in WORTH appear the value of the product that is recorded in my table , and if in the quantity I chose some value greater than 1 no Total Value appear the sum in the exact amount.

My table : inserir a descrição da imagem aqui

2 answers

1


A functional example, it’s up to you to adapt to your case:

Select pulling all companies from the bank, call an event on onchange that will fill in the inputs according to the values searched in the database:

  <select class="select" id="numEmpresa" name="numEmpresa" onchange='empresa(this.value,this.id)' autofocus required>
     <option value='-1'>Digite N&ordm; da Empresa</option>
      <?php  foreach($empresas as $row){  ?> 
      <option value='<?=$row['num_empresa']?>'>
      <?=$row['num_empresa']?> - <?=$row['nm_empresa']?>
     </option> 
     <?php } ?>
  </select>

The event onchange company, takes the value of select and fills in the input honorary

 <!-- Buscar Empresas -->
    <script type='text/javascript'>
    function empresa(id,select){
      $('#honorario').attr("disabled",false);
      $.post("autoCompleteSelect.php",{idEsc:id},function(retorno){
          $('#honorarios').val(retorno);
        }
      });
    }
    </script>
    <!-- ./ Buscar Empresas -->

Populate input according to function return:

<input type="text" id="honorarios" name="honorarios" >  

The Script (autoCompleteSelect.php) that is called within the event enterprise, pulls from the bank the value of the input honorary and returns to function

$id = (int)$_POST['idEsc']; // id passado pelo select

list($resultados,$quantidade) = $select->selectTable('empresa','valor',NULL,"numero=".$id,NULL);

if($quantidade>0){
    foreach ($resultados as $row) {
        $dados = str_replace(".",",", $row['valor']);
    }
}else{
    $dados = '';
}

echo $dados;
  • Opa Bia , I’m sorry for the delay in responding , but could you give me an explanation of how to use this code ? I tried here a few times but could not adapt

  • @Matheusgoes The first part is the select that has the names of the companies, according to the company that selects the value of the fee field (honorary input) is filled in according to the drawn value of the bank. The onchange script is responsible for calling the select (autoCompleteSelect.php) that searches the database. autoCompleteSelect.php is a separate file, in it Voce has access to the bank and looks for the necessary elements, in case the fee value to fill the honorary inputs.

  • @Matheusgoes friend I know that my answer was very direct, watch this video that does the same thing of this script: https://www.youtube.com/watch?v=j4HMjjPj5IU, I’m sure you will get it so.

  • 1

    Very obg , I managed to do following this video lesson :)

0

This function does the following: Each time you change there in the combobox it displays the value you selected, this way you can switch instead of displaying you make it show the value of the product. Simple but very useful. I hope it helps you and everyone who are having the same difficulty.

<hmtl>
  <script>
    function b(){
      var i = document.f.estado.selectedIndex;
     // alert(document.f.estado[i].text);
     document.getElementById('valor').value = document.f.estado[i].text;
    }
  </script>
 <body>
  <form name="f">
    <select name="estado" onchange="b()">
     <option value="pd1">produto1</option>
     <option value="pd2">Produto2</option>
     <option value="pd3">produto3</option>
    </select>
  </form>

 <input type="text" name="valor" id="valor" value="">

 </body>
</html>

to fill in the input just use: Document.getElementById('value'). value = Document.f.status[i]. text;

where the "value" is the input id, and . value = "here is what would be placed in the input".

  • Opa tried here , but it was not so I wanted , I would like the value of the product to be within the 'input value' and not in an Alert

  • Yes that was an example of how you could do, For you to fill in the input just do so > Document.getElementById('value'). value = "Valoresss"; It is obvious that you would change the "Valoresss" to the value of the product you receive from php.

Browser other questions tagged

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