send arrangements from ajax

0

GOOD I am trying to send an ajax array to java but it only sends me a data and I want it to send the ones I choose in the checkbox

function checkBoxElm_fav() {
  var Selec = document.getElementById("Selec").value;
  alert("cheked" + Selec);
  $.ajax({
    type: "POST",
    dataType: 'text',
    url: "bandeja_entrada.htm",
    data: {
      'Selec': Selec
    },
    success: function(response) {

      window.location.replace("bandeja_entrada.htm");

    },
  });



}



function elim_fav() {
  alert("entre");
  checkBoxElm_fav();
  var d = document.getElementById("Selec").value;


}
<a onclick="elim_fav()" name="prueba" id="prueba" title="Borrar Usuarios" class="text-left"><span class="icon"><i class="icon-trash"></i></span></a>
<table id="tb_com" class="table table-bordered ">

  <thead>
    <tr>
      <th></th>
      <th>favorito</th>
    </tr>
  </thead>
  <tbody>
    <c:forEach items="${favorito_foreach}" var="dato">
      <td><input type="checkbox" name="Selec[]" id="Selec" value="${dato.idFavorito}" /></td>
      <td>
        <c:out value="${dato.favorito}" />
      </td>


    </c:forEach>
  </tbody>
</table>

checkbox

    
asked by Kevin Castaño 31.07.2017 в 20:53
source

1 answer

0

here is an example with javascript of what you should do; first search by name for Selec functions when clicking on a button; then valid which line was not selected; in the end you send it;

    function checkBoxElm_fav(unSelected) {
      jQuery.ajax({
        type: "POST",
        dataType: 'text',
        url: "bandeja_entrada.htm",
        data: {
          'Selec': unSelected
        },
        success: function(response) {

          window.location.replace("bandeja_entrada.htm");

        },
      });
    }
    function elim_fav() {
      let d = document.getElementsByName("Selec");
      let valoresEnviar =[];
      for (let i = 0; i < d.length; i++){
      if (d[i].checked) continue;
       valoresEnviar.push(d[i].value);
        
      }
      console.log("enviar" , valoresEnviar );
      checkBoxElm_fav(valoresEnviar);


    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a onclick="elim_fav()" name="prueba" id="prueba" title="Borrar Usuarios" class="text-left"><span class="icon"><i class="icon-trash"></i></span></a>
    <table id="tb_com" class="table table-bordered ">

      <thead>
        <tr>
          <th></th>
          <th>favorito</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td><input  type="checkbox" name="Selec" value="2" /></td>
          <td>
            favorito 2
          </td>
</tr>
        <tr>
          <td><input  type="checkbox" name="Selec" value="1" /></td>
          <td>
            favorito 1
          </td>
</tr>
      </tbody>
    </table>
    <button onclick="elim_fav()">Enviar</button>
    
answered by 31.07.2017 / 21:28
source