How to submit form when selecting checkbox?

0

I have a form in html, sending data to the php code, but I use the input type="submit" button to send the data and I wanted the checkbox to send the form. Here is my code below:

    insira o código aquiecho '<tr>';
      echo '<form id="teste" action="banco.php" method="post"><td><input  id="check" name="bike'.$fetch['id'].'" type="checkbox"  onclick="document.getElementById("teste").submit()" value="on" class="confirmacoes"><a href="banco.php"> </a></td><form>';

      echo '<td >'.$fetch['id'].'</td>';
      echo '<td >'.$fetch['turno'].'</td>';


      echo '<td>'.$fetch['data'].'</td>';
      echo '<td>'.$fetch['tubetes_prod'].'</td>';
      echo '<td>'.$fetch['tubetes_caixadetubete'].'</td>';
      echo '<td>'.$fetch['logs_rebobinados'].'</td>';
      echo '<td>'.$fetch['logs_colados'].'</td>';
      echo '<td>'.$fetch['logs_acumulador'].'</td>';
      echo '<td>'.$fetch['rolo_produzido'].'</td>';

      echo '<td><a id="logo-container" href="'.$fetch['tipo_prod'].'" class="brand-logo"><img src="teste.png"  /></a></td>';
      echo '<td><a id="logo-container" href="'.$fetch['tipo_prod'].'" class="brand-logo"><img src="teste.png"  /></a></td>';
      echo '<td><a id="logo-container" href="'.$fetch['tipo_prod'].'" class="brand-logo"><img src="teste.png"  /></a></td>';
      echo '<td><a id="logo-container" href="'.$fetch['tipo_prod'].'" class="brand-logo"><img src="teste.png"  /></a></td>';
      echo '<td><a id="logo-container" href="'.$fetch['tipo_prod'].'" class="brand-logo"><img src="teste.png"  /></a></td>';
      echo '<td><a id="logo-container" href="'.$fetch['tipo_prod'].'" class="brand-logo"><img src="teste.png"  /></a></td>';
      echo '<td><a id="logo-container" href="'.$fetch['tipo_prod'].'" class="brand-logo"><img src="teste.png"  /></a></td>';
       $i++;
  };

  echo"<input type='submit' id='teste' name='teste'>";
    
asked by anonymous 09.10.2018 / 15:31

3 answers

0

Set onChange="this.form.submit()" within the <input /> x tag of the checkbox.

    
09.10.2018 / 16:08
0

With the select you can do

<select name="cidade" onsubmit="myFunction()">
           <option value="São Paulo">São Paulo</option>
 </select>

With Checkbox I believe that below the selection you need a submit button

    
09.10.2018 / 15:59
0

I believe you can do this using javascript. Here is an example:

<input  id="check" name="bike'.$fetch['id'].'" type="checkbox" onclick="myFunction()" value="on" class="confirmacoes">

You need to declare the function:

<script>
function myFunction() {
    document.getElementById("teste(id do seu formulario)").submit();
}
</script>
    
09.10.2018 / 16:05