1

i have to html files 1st is a table with a boton in the last column, the 2nd is a html file with an image so i need to clic the table row and print this values over the secont html file, is a certificate with values has name and chronometer time, the finale objetive is to print in pdf but now i am trying to move table row data to the certificate.

thnaks a lot for help

this si the code i try on firts html file:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js" type="text/javascript"></script>

<script>
    //  function myFunction() {
    //    var myWindow = window.open("", "", "width=600,height=400");
    //   myWindow.document.write("valores+=$(this).html()+"\n");
    //   var valores="";
    //  $(this).parents("tr").find("td").each(function(){
    //               valores+=$(this).html()+"\n";
    //                                                  });
    //                              });

    $(document).ready(function() {
        $(".boton").click(function() {

            var myWindow = window.open("cert.html", "_blank", "width=1090,height=860");
            var valores = "";

            // Obtenemos todos los valores contenidos en los <td> de la fila
            // seleccionada
            $(this).parents("tr").each(function() {
                valores += $(this).html() + "\n";
                //valores = valores + "</br></br>";
            });

            //  myWindow.document.write(valores+ "<body background='plantilla.png'/>");
            //       myWindow.document.write("<span class='green'>The score you entered is:"   + valores +   ".Your letter grade is: B!</span>");
                 myWindow.document.write(valores);

           // myWindow.document.write(valores);

            // alert(valores);
        });
    });
</script>

<style>
    myWindow {
        background-image: url("cedulalmma.jpg");
    }

    .boton {
        border: 1px solid #808080;
        cursor: pointer;
        padding: 2px 5px;
        color: white;
    }
</style>

<table border="1" cellspacing="2" cellpadding="5">
    <tr>
        <td>val 1</td>
        <td>val 2</td>
        <td>val 3</td>
        <td class="boton"></td>
    </tr>
    <tr>
        <td>val 4</td>
        <td>val 5</td>
        <td>val 6</td>
        <td class="boton"></td>
    </tr>
    <tr>
        <td>val 7</td>
        <td>val 8</td>
        <td>val 9</td>
        <td class="boton"></td>
    </tr>
</table>

LUIS
  • 11
  • 1
  • 1
    Your solution isn't gonna work as it is. You need "something" to pass data between the pages. A cookie, data storage, loading the second page using AJAX in the same page or a server side language would be alternatives. – Skaparate Dec 28 '18 at 20:56
  • the principal table is made by an timing app and the exit is a html page with results, so there is java or php... is posible move the data with ajax? can you give me a clue? thnaks for your time – LUIS Dec 28 '18 at 20:57

1 Answers1

1

Here is one way to do it.

Modify your table script like this:

<script>
    $(document).ready(function() {
      $(".boton").click(function() {
        var valores = "";
        // $(this).siblings() retrieves every adjacent td of the current one
        $(this).siblings().each(function() {
          valores += $(this).html() + "\n";
          //valores = valores + "</br></br>";
        });

        var myWindow = window.open("cert.html", "_blank", "width=1090,height=860");
        // Here You assing the values to a window property:
        myWindow.valores = valores;
      });
    });
</script>

Then, in your second HTML page, load jQuery and you could get the values like this:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js" type="text/javascript"></script>
<script>
    $(document).ready(function() {
        // Here you can manipulate the however you like
        console.log(window.valores);
    });
</script>

If the server needs to parse the file (because it needs a key or something that only the server has), then You need to send the data to it using POST, as You can see here.

Hope it helps.

Skaparate
  • 489
  • 3
  • 14