Add product value for purchase

0

Well, guys, I have the following difficulty, I have a very simple sales panel:

AsyoucanseeIhaveacomboboxwithsomeproductsinit,myproblemandthefollowingIwouldneedassoonasIchoseanyoftheproductsthere,automaticallyinVALUEitisrecordedinmytable,andifincaseofquantityIwouldchoosesomevaluegreaterthan1inTotalValuewouldappearthevalueaddedintheexactquantity.

Mytable:

    
asked by anonymous 30.12.2015 / 19:13

2 answers

1

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

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

  <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 the select and fills the input fees

 <!-- 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 -->

Fill in the input according to the function return:

<input type="text" id="honorarios" name="honorarios" >  
Script (autoCompleteSelect.php) that is called within the company event, pulls the value of the input fees from the database 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;
    
30.12.2015 / 19:48
0

This function does the following: Each time you change there in the combobox it displays the value you selected, this way you can change instead of displaying you make it show the value of the product. Simple yet very useful. I hope it helps you and everyone who has 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.estate [i] .text;

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

    
30.12.2015 / 19:38