Take checkbox values with javascript and view database data

Asked

Viewed 230 times

1

I’m making a shopping cart in PHP. I have two checkbox (Fetch at the counter and Delivery) and need that at the moment the user click on the checkbox Delivery the value of the delivery fee from the Bank is calculated with the total order.

My code:

      <form action"conteudo.php" name="frm" method="GET">
            <span class="servicos"><input id="bus"type="radio" name="rad" value="1">             Buscar no balcão<br>
        </span>
            <span class="servicos"><input id="bus"type="radio"name="rad" value"2"> Entrega</span>
                    </form>

    `<table width="310" border="1">
                      <thead>
                        <tr>
                          <td>Excluir</td>
                          <td>Qtde</td>
                          <td>Produto</td>
                          <td>Valor</td>       
                        </tr>
                        <br>
                      </thead>
                      <tbody>
                           <?php
                          foreach ($_SESSION['carrinho'] as $id => $qtde) {
                            $sql = "SELECT * FROM produto WHERE ID_PRODUTO = '$id'";
                            $end = mysqli_query($con,$sql);
                            while($resu = mysqli_fetch_assoc($end)){

                            $nome  = $resu['NOME_PRO'];
                            $preco = FormataValor($resu['PRECO_P']);
                            $sub   = $resu['PRECO_P'] * $qtde;
                            $total += $sub ;

                            <tr>
                              <td><a href="?acao=del&id='.$id.'">&#10148;</a></td>
                              <td>'.$qtde.'</td>
                              <td>'.$nome.'</td>
                              <td>R$'.$preco.'</td>
                            <tr>  
                              <td colspan="4"></td>
                            </tr>
                            <tr>  
                              <td colspan="4"></td>
                            </tr>';
                               }
                           }

                          ?> 

                     </tbody>

                     <tfoot>
                        </form>
                        <tr>  
                            <td colspan="4"></td>
                            </tr>
                            <tr>  
                            <td colspan="4"></td>
                            </tr>  
                        <tr>  
                          <td colspan="3">SubTotal</td>
                          <td>R$<?php echo FormataValor($total);?></td>
                        </tr>
                        <tr>  
                          <td colspan="3">Taxa Entrega</td>
                          <td><?php 
                          if(isset($_GET['rad'])){
                            echo $resu['TAXA_ENTREGA'];}?></td>
                        </tr>
                        <tr>  
                          <td colspan="3">Total</td>
                          <td>R$<?php echo FormataValor($total) ;?></td>
                        </tr>
                    </tfoot>
                  </table>
                  <a href="index.php">Continuar Comprando</a`>
  • That code you posted on it?

  • Ola Marconi, this code is a shopping cart,made in php, when I add a product I can delete the product, calculate the total and subtotal , what I wish to do is from the checkbox is to bring a value of bank delivery rate to the user , when you click on the check delivery already add the sample delivery rate 2.00 that amount coming from the bank and at the same time calculate in total

  • When you say database you mean database or literally database?

  • Database I am using MYSQL

  • I’ll give you a hint, you could create a data attribute (example data-rate) in the checkbox and manipulate this value by Javascript when it clicks the checkbox, just to show the user. Already in php, repeat the process to not give margin for change.

  • I’m sorry Lucao, I’m very lay I still can’t quite understand your suggestion

Show 1 more comment
No answers

Browser other questions tagged

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