Send combobox and checkbox data to another table

Asked

Viewed 113 times

0

First of the button submit who loses the action when I put my script to configure my table. Second I need to do some steps:

  1. I carry a combobox with data from a given table, that is, names of some collaborators.

  2. I load my table with data from another table, clients name.

  3. I need to select the name of a collaborator and one or several clients through checkbox in the table and send these data to another table. In other words, the table will be composed by the employee ID linked to the Client ID, which in this case would be the collaborator responsible for those customers.

Javascript

<script>
    $(function(){

      $('table > tbody > tr:odd').addClass('odd');

      $('table > tbody > tr').hover(function(){
        $(this).toggleClass('hover');
      });

      $('#marcar-todos').click(function(){
        $('table > tbody > tr > td > :checkbox')
          .attr('checked', $(this).is(':checked'))
          .trigger('change');
      });

      $('table > tbody > tr > td > :checkbox').bind('click change', function(){
        var tr = $(this).parent().parent();
        if($(this).is(':checked')) $(tr).addClass('selected');
        else $(tr).removeClass('selected');
      });

      $('form').submit(function(e){ e.preventDefault(); });

      $('#pesquisar').keydown(function(){
        var encontrou = false;
        var termo = $(this).val().toLowerCase();
        $('table > tbody > tr').each(function(){
          $(this).find('td').each(function(){
            if($(this).text().toLowerCase().indexOf(termo) > -1) encontrou = true;
          });
          if(!encontrou) $(this).hide();
          else $(this).show();
          encontrou = false;
        });
      });

      $("table") 
        .tablesorter({
          dateFormat: 'uk',
          headers: {
            0: {
              sorter: false
            },
            5: {
              sorter: false
            }
          }
        }) 
        .tablesorterPager({container: $("#pager")})
        .bind('sortEnd', function(){
          $('table > tbody > tr').removeClass('odd');
          $('table > tbody > tr:odd').addClass('odd');
        });

    });
    </script>

HTML / PHP

<html>
  <head>
   <meta charset="utf-8" />

    <link rel="stylesheet" type="text/css" href="_css/_cadastro.css"/>
    <link rel="stylesheet" type="text/css" href="_css/form.css"/>
    <link rel="icon" href="_imagens/icone.ico">
    <script language="JavaScript" src="../js/dataCad.js"></script>
    <script language="JavaScript" src="../js/formatarMascara.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
    <script src="jquery.tablesorter.min.js"></script>
    <script src="jquery.tablesorter.pager.js"></script>
    <link rel="stylesheet" href="custom.css" media="screen" />
  </head>
  <body>

  <?php
        include_once("conexao2.php");

        $sqlProfessor="SELECT IdProf, NomeProf FROM professor" ;

        $resultado = mysqli_query($conn,$sqlProfessor);

        ?>

  <div id="interface">
    <header id="cabecalho">
        <hgroup>
            <h1>Clínica Escola</h1>
            <h2>Cadastro</h2>
        </hgroup>

         <img id="imgpos" src="../_imagens/psicologia.png"/>
        <img id="imgpos2" src="../_imagens/logo-pitagoras.png"/>
    </header>

    <header id="corpo">


    <form >
    <div id="formulario">

             <div class="esquerda" id="">


         <label for="">Selecione um Professor</label>
         <select name="professor" >
         <option>Selecione...</option>

         <?php while($prod = mysqli_fetch_assoc($resultado)) { 
        echo '<option value="'.$prod['IdProf'] .'">'.$prod['NomeProf'].'</option>'."\n";

          } 
          ?>

         </select>

            </div>
        </div>
    </form> 
<br>
<br>
<br>

    <form  method="post" action="testaPHP.php" >
      <p>
        <label for="pesquisar">Pesquisar</label>
        <input type="text" id="pesquisar" name="pesquisar" size="30" />
      </p>
    </form>

    <?php

        $sql="SELECT c.IdCliente,c.NomeCliente,c.IdadeCliente,c.Celular,s.NomeStatus FROM cliente c,Status s WHERE c.IdStatus=s.IdStatus" ;

        $result = mysqli_query($conn,$sql);


    echo"
    <table cellspacing='0'>
      <thead>
        <tr>
          <th><input type='checkbox' value='1' id='marcar-todos' name='marcar-todos' /></th>
          <th>ID</th>
          <th>Nome</th>
          <th>Idade</th>
          <th>Telefone</th>
          <th>Status</th>
          <th>Ações</th>
        </tr>
      </thead>";

      while($escrever=mysqli_fetch_array($result)){
          foreach($escrever AS $key => $value) { $escrever[$key] = stripslashes($value); }

      echo "<tbody>";
       echo" <tr>";
  echo "<td valign='top'><input type='checkbox' name='ativo[]'value={$escrever['IdCliente']}>";
        echo"<td>".$escrever['IdCliente']."</td>";
          echo"<td>".$escrever['NomeCliente']."</td>";
          echo"<td>".$escrever['IdadeCliente']."</td>";
         echo" <td>".$escrever['Celular']."</td>";
          echo"<td>".$escrever['NomeStatus']."</td>";
          echo"<td>";
           echo" <a href='#'><img src='edit.png' width='16' height='16' /></a>";
           echo" <a href='#'><img src='delete.png' width='16' height='16' /></a>";
          echo"</td>";
        echo"</tr>";
      echo"</tbody>";
      }
    echo"</table>";

    ?>

    <div id="pager" class="pager">
        <form>
                <span>
                    Exibir <select class="pagesize">
                            <option selected="selected"  value="10">10</option>
                            <option value="20">20</option>
                            <option value="30">30</option>
                            <option  value="40">40</option>
                    </select> registros
                </span>

                <img src="first.png" class="first"/>
            <img src="prev.png" class="prev"/>
            <input type="text" class="pagedisplay"/>
            <img src="next.png" class="next"/>
            <img src="last.png" class="last"/>
        </form>
    </div>
    <br>
<br>
<br>
<br>
<br>
<br>
    <form name="prof" method="post" action="check.php">
        <input type="submit" /> 
    </form> 

  </body>
</html>
  • What logic did you think when doing the preventDefault of the event submit forms? You know what this line does?

  • Anderson, actually I have little knowledge in html and php, it was to be developed in java web,

  • Anderson actually I’m reusing the code and was unaware of this functionality, I commented him here and did not interfere in anything, your help has been worth now I’ll try the rest, you have any idea?

  • This code prevented the form from being submitted. I hope that now the first problem has been solved. The second one is very confusing. If you can present a [mcve], I believe it will facilitate understanding.

  • Anderson, Thanks for the help I managed to resolve here. Your help was critical

No answers

Browser other questions tagged

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