Run Javascript code on another page from a button

Asked

Viewed 46 times

0

When I click the button Simulate it adds lines (as per JS code) on the same page...

But I would like to know what I need to do for these lines to be generated on another page, that is, after clicking the button it redirects to another page and generates tables.

OBS1: Input parameters are provided by the user on the page where the simulate button is located.

OBS2: The JS code is responsible for creating the elements td

SIMULATE BUTTON

<button id="simular" type="button" style="margin-top: 15px;"  class="btn btn-primary" >Simular</button>

TABLE TO BE GENERATED ON THE OTHER PAGE

<table id="tabela1" border="1">
    <thead id="cabecalho">
        <th>Info A</th>
        <th>Info B</th>
        <th>Info C</th>
        <th>Info D</th>
        <th>Info E</th>
    </thead>
    <tbody>
       <td>

       </td>
    </tbody>
</table>

BUTTON CODE IN THE JS FILE

botao_simular.addEventListener('click', simular);

JS CODE FOR GENERATING LINES

function simular(event) {
  event.preventDefault();
  var media = campo1.value;
  if ( media >= 131 && media <= 10000) {
      nova_simulacao = new Opcao1 (campo_nome.value, campo1.value);

  } else {
      document.querySelector(".alerta").innerText = "A média deve ser maior que 130 e menor que 10.000"; 
  };
};
  • Good afternoon. What would that "Other HTML"?

  • 1

    Another page I created to show the result of my JS code. However the input parameters are informed by the user on this first page.. when he clicks on the simulate I need him to go to another page where the results will appear.

  • And where’s the code on the other page?

  • You need the data the user enters on the other page, is that it? If so, have you tried using sessionStorage?

  • I closed the question as "need more details and clarification". Please@Francomotta, if you want to reopen the question, add more details or more information than you need.

  • @Wallacemaxters already edited and I was as clear as possible. If you can open the question again thank you, or I will have to do another.

  • @Jaderson the sessionStorage should include inside the button JS code?

  • It can be at the click of the button... I would create a function to save in sessionStorage all the data you need on the other page and also create a function to recover that data. So you call the roles when necessary. This link gives you a quick idea of how to use the resource: https://www.treinaweb.com.br/blog/quando-usar-sessionstorage-e-localstorage/

Show 3 more comments
No answers

Browser other questions tagged

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