How to send form when selecting checkbox?

Asked

Viewed 916 times

0

I have a form in html, sending data to php code however I use the button input type="submit" to send the data and wanted to send the form by clicking the checkbox. Follow 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'>";

3 answers

0

With 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 button of type Submit

0

I believe you can do this using javascript. Follow 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>
  • What would this test be before the id of my form?

  • your form is with this id, it was just for you to understand. It would look like this: Document.getElementById("test"). Submit();

0


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

Browser other questions tagged

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