0

I need guidance according to this code, how to send the table drawn in the index by email?,how to make the information that comes from the form and is grouped in the table, can be sent by mail? This code that was published here is a good example.Since the need I have to learn is simplified with this code, there is a table with data entered from the inputs, but how can it be sent?

  $(document).ready(function() {
//obtenemos el valor de los input

$('#adicionar').click(function() {
  var nombre = document.getElementById("nombre").value;
  var apellido = document.getElementById("apellido").value;
  var cedula = document.getElementById("cedula").value;
  var i = 1; //contador para asignar id al boton que borrara la fila
  var fila = '<tr id="row' + i + '"><td>' + nombre + '</td><td>' + apellido + '</td><td>' + cedula + '</td><td><button type="button" name="remove" id="' + i + '" class="btn btn-danger btn_remove">Quitar</button></td></tr>'; //esto seria lo que contendria la fila

  i++;

  $('#mytable tr:first').after(fila);
    $("#adicionados").text(""); //esta instruccion limpia el div adicioandos para que no se vayan acumulando
    var nFilas = $("#mytable tr").length;
    $("#adicionados").append(nFilas - 1);
    //le resto 1 para no contar la fila del header
    document.getElementById("apellido").value ="";
    document.getElementById("cedula").value = "";
    document.getElementById("nombre").value = "";
    document.getElementById("nombre").focus();
  });
$(document).on('click', '.btn_remove', function() {
  var button_id = $(this).attr("id");
    //cuando da click obtenemos el id del boton
    $('#row' + button_id + '').remove(); //borra la fila
    //limpia el para que vuelva a contar las filas de la tabla
    $("#adicionados").text("");
    var nFilas = $("#mytable tr").length;
    $("#adicionados").append(nFilas - 1);
  });
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
  <form>
   <div class="form-group">
    <p>
      <label>Entre su Nombre:</label> <br>
      <input id="nombre" class="form-control" type="text" placeholder="Nombre..."><br>
    </p>
    <p>
      <label>Entre su Apellido:</label> <br>
      <input id="apellido" class="form-control" type="text" placeholder="Apellido..."><br>
    </p>
    <p>
      <label>Entre su C&eacute;dula:</label> <br>
      <input id="cedula" class="form-control" type="text" placeholder="Cedúla"> <br>
    </p>
    <button id="adicionar" class="btn btn-success" type="button">Adicionar a la tabla</button>
  </div>
</form>

<p>Elementos en la Tabla:
  <div id="adicionados"></div>
</p>
<table  id="mytable" class="table table-bordered table-hover ">
  <tr>
    <th>Nobmre</th>
    <th>Apellidos</th>
    <th>C&eacute;dula</th>
    <th>Eliminar</th>`enter code here`
  </tr>
</table>
  • 1
    You want to open the users email client with a prepopulated body of the table? Or you want to send an email directly from code? [The latter cannot be done from the browser](https://stackoverflow.com/questions/7381150/how-to-send-an-email-from-javascript), although a request could be sent to a server and it could be executed in server code. [Table markup _should_ be supported in an email](https://stackoverflow.com/questions/6115197/embed-html-table-in-email), although the process of putting html in emails has a reputation of being rather tricky. – Alexander Nied Jul 17 '21 at 01:27

0 Answers0