• 0
Sign in to follow this  
Diego Alexandre Dias

Problema com checkbox php

Question

 

Boa tarde amigos , 

Estou desenvolvendo um sistema para minha empresa , que tem como finalidade acompanhar a verba de mídia destinada para cada unidade de negócio .. 

Basicamente e o que tenho pronto são chekbox que indicam quais unidades receberam o rateio de determinado valor de uma nota fiscal .. cada checkbox possui um value referente ao número de habitantes . 

Possuo uma function que soma todos os checkbox assinalados e me retorna esta soma numa text. 

A partir deste ponto começa a dificuldade , pois preciso calcular o quanto cada unidade assinalada representa do total (presente na function)

em percentual. Posteriormente preciso que este resultado seja meu value e que consequentemente irá para meu banco .  Deste modo saberei o quanto cada unidade vai receber na divisão das despesas em reais. 

alguém tem alguma ideia de função que faça este cálculo ? 

 

<!DOCTYPE html>

<html lang="pt-br">

  <head>

    <meta charset="utf-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1">

  

    <meta name="description" content="Página Administrativa">

    <meta name="author" content="Diego">

    <link rel="icon" href="imagens/favicon.ico">

 

    <title>Cadastrar Nota Fiscal</title>

   

    <link href="css/bootstrap.min.css" rel="stylesheet">

   

    <link href="css/bootstrap-theme.min.css" rel="stylesheet">

    

    <link href="css/ie10-viewport-bug-workaround.css" rel="stylesheet">

  

    <link href="theme.css" rel="stylesheet">

 

    <script src="js/ie-emulation-modes-warning.js"></script>

    

  </head>

 

  <body role="document">

 

    <?php

 

      include_once("menu_admin.php");

      

    ?>

    

    <div class="container theme-showcase" role="main">

      

      <div class="page-header">

        <h1>Lançamento de Nota Fiscal</h1>

      </div>

 

 

   <div class="row">

   

   <!--

          <div class="pull-rigth">

 

           <a href='administrativo.php?link=11<?php echo $resultado ['id']; ?>'> <button type='button' class='btn btn-sm btn-info'>Listar</button></a>

         

          </div>-->

 

 

        </div>

      <div class="row">

        <div class="col-md-12">

 

 

          <form class="form-horizontal" method="POST" action="processa/processa_cad_produto.php" enctype="multipart/form-data">

    

                <div class="form-group">

    <label for="inputPassword" class="col-sm-2 control-label">Descrição Contábil</label>

    <div class="col-sm-10">

      <select class="form-control" name="situacao_id">

        

      <option>Selecione</option>

                

      <?php

       $resultado = mysqli_query($conectar,"SELECT * FROM situacao");

       while ($dados = mysqli_fetch_assoc($resultado)){

        ?>

 

        <option value="<?php echo $dados["id"];?>"><?php echo $dados["nome"]; ?> </option>

        <?php 

      }

      ?>

       

        </select>

    </div>

     </div>            

                

  <div class="form-group">

    <label for="inputEmail3" class="col-sm-2 control-label"> Despesa</label>

    <div class="col-sm-10">

      <input type="text" class="form-control" name = "nome" placeholder="Informe o tipo de Despesa">

    </div>

 

 

     <div class="form-group">

    <label for="inputEmail3" class="col-sm-2 control-label">Observação</label>

    <div class="col-sm-10">

      <textarea class="form-control ckeditor"  rows="5" name ="descricao_longa" placeholder= "Descricao Longa do Produto"></textarea>

    </div>

     </div>

 

<div class="form-group">

    <label for="inputEmail3" class="col-sm-2 control-label">preço</label>

    <div class="col-sm-10">

      <input type="text" class="form-control" name = "preço" placeholder="preço do Produto">

    </div>

 

  </div>                                

                                               

                                               <input type="checkbox" name="valor1"  value= "127224">Agua Verde<br/>

                                                                 

                                               <input type="checkbox" name="valor2" value= "127224">AHU<br/>     

                                                  

                                               <input type="checkbox" name="valor3" value= "127224">BACACHERI<br/>       

                                                                                              

                                               <input type="checkbox" name="valor4" value= "127224">CAJURU<br/>              

                                  

                                               <input type="checkbox" name="valor5" value= "127224">CENTRO<br/>             

                   

                                               <input type="checkbox" name="valor6" value= "127224">MERCES<br/>             

                                  

                                               <input type="checkbox" name="valor7" value= "127224">NOVO MUNDO<br/> 

                                 

                                               <input type="checkbox" name="valor8" value= "127224">KENNEDY<br/>           

                   

                                               <input type="checkbox" name="valor9" value= "127224">PORTÃO<br/>             

                                  

                                               <input type="checkbox" name="valor10" value= "127224">STA. FELICIDADE<br/>          

                  

                                               <input type="checkbox" name="valor11" value= "127224">CHAMPAGNAT<br/>             

                               

                                               <input type="checkbox" name="valor12" value= "127224">ECOVILLE<br/>         

                

                                               <input type="checkbox" name="valor13" value= "127224">ALTO XV<br/>          

                               

                                               <input type="checkbox" name="valor14" value= "127224" >BATEL<br/>              

                                               

                   

            <input type="text" name="valor15" id="result" value= "0.00">

                                                                                                                              

                                                      

  <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">

      <button type="submit" class="btn btn-success">Cadastrar</button><br/>   <br/>    

    </div>

  </div>

</form>

       

        </div>

      </div>

        </div> <!-- /container -->

 

    <script src="js/jquery.min.js"></script>    

    <script src="js/bootstrap.min.js"></script>

    <script src="js/docs.min.js"></script>

    <script src="js/ie10-viewport-bug-workaround.js">

    <script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script>

    </script>

    </body>

  

  <script> 

                               function somar() {

                                               var result = $("input:checked");

                                               var total = 0;

 

                                               for (var i=0; i<result.length; i++)

                                               {

                                                               total = total + parseFloat(result.value);

                                                                                              }

                                                                                              $("#result").val(total.toFixed());

                               }

                               somar();

                               $(":checkbox").click(somar);

                               </script>

  

</html>

Share this post


Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this