Save to database via javascript

Asked

Viewed 494 times

0

My doubt consists in the following, I have the following form

<form name="frm_warning" id="box-register" method="POST" action="controllerWarning.php">
            <h2 class="m-t-0 m-b-15">Warning</h2>
             <div class="card">
                <div class="card-body">
                    <div class="table-responsive">
                        <table id="data-table" class="table">
                            <thead>
                                <tr>
                                    <th>Chamado Numero</th>
                                    <th>Nome</th>
                                    <th>Telefone</th>
                                    <th>Numero de tentativas</th>
                                    <th>Ultima Tentativa</th>
                                    <th>Zerar Tentativas?</th>
                                </tr>
                            </thead>
                            <tbody>


                                <?php 

                                    $query = sprintf("select * from ivr_contatos, ivr_campanha,ivr_business where ivr_contatos.campanha = ivr_campanha.id and ivr_business.idvisita = ivr_contatos.codigo and ivr_contatos.status = 0 and tentativas >= qtdtentativas" );
                                    $result = Populator::ConsultaDB($query);

                                    while ($resultado = pg_fetch_array($result) ) {
                                        $chamado = $resultado['numerochamado'];
                                        $nome = $resultado['nome'];
                                        $telefone = $resultado['telefone'];
                                        $tentativa = $resultado['tentativas'];
                                        $lastAttempt = $resultado['atualizado'];
                                        $dataconvertida = date('d/m/Y H:i:s', strtotime($lastAttempt));
                                        $codigo = $resultado['codigo'];

                               echo '         

                                <tr>
                                <td align="center">'.$chamado.'</td>
                                    <td>'.$nome.'</td>
                                    <td>'.$telefone.'</td>
                                    <td align="center">'.$tentativa.'</td>
                                    <td>'.$dataconvertida.'</td>
                                    <td><input type="checkbox" class="marcar" id="check" value='.$codigo.' name="check[]"/></td>
                                </tr>
                                ';
                                    }
                                ?>


                            </tbody>
                        </table>
                    </div>
                </div>
            </div>

            <input type="button" value="Salvar" onclick="Confirma()" class="btn btn-sm m-r-5" />

            <p id="demo"></p>

        </form>

where I call a confirmation message via javascript:

<script type="text/javascript">
            function Confirma(){
                var txt;
                if(confirm("Deseja zerar as tentativas dos contatos selecionados?")){
                    txt = "Zerou as tentativas";
                }else{
                    txt = "Não zerou as tentativas";
                }
                     document.getElementById("demo").innerHTML = txt;
            }
        </script>

where is the field txt = "Reset attempts"; I would like to send to the controllerwarning.php action which is where I do the inclusion in the action database I am performing.

  • You want to send the string to php?

  • Not necessarily, the idea is after the guy confirms, that he called my controllerWarning.php which is where I run the actions in the database

  • But what exactly will pass to controllerWarning.php ?

  • it already passes the combobox data, I just wanted to know to give the javascript Ubmit for the controllerWarning.Pgp

  • then is already well answered by @Guilhermecostamilam

1 answer

0


I don’t quite understand if you want this inside the if or of else, but just change:

//Funções, exceto construtoras, devem iniciar com minúsculas e com um verbo no infinitivo (convenção criada para tentar padronizar os códigos)
function confirmar() {
  var txt;
  if(confirm("Deseja zerar as tentativas dos contatos selecionados?")) {
    //Chama o método submit do formulário com o id box-register
    document.getElementById('box-register').submit();
    txt="Zerou as tentativas";
  } else {
    txt="Não zerou as tentativas";
  }
  document.getElementById("demo").innerHTML=txt;
}
<form name="frm_warning" id="box-register" method="POST" action="controllerWarning.php">
  <h2 class="m-t-0 m-b-15">Warning</h2>

  <! ... >

  <input type="button" value="Salvar" onclick="confirmar()" class="btn btn-sm m-r-5" />
</form>

  • It was exactly this point that I wanted, give Ubmit through javascript

Browser other questions tagged

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