Explanation:
When you send the form from page 1 to page 2 it creates "Parameters" at page 2 url
For example: http://127.0.0.1/pagina2.html?nome=Fulano&nascimento=01/01/1990
The function you are using takes these parameters from the url, but only one at a time.
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
That is, if you want to take more than one parameter and put it somewhere, you will need to put one by one on page 2
As in the following example:
If on your page 2 there is an html like this:
<div class="conteudo">
Seu nome é: <span id="nome"></span><br>
Sua data de nascimento é: <span id="nascimento"></span>
</div>
To print the parameter values on each span of these, you will need to identify each span, as I did by giving an "id" pro span.
for example, if you want to take Cpf, it would be as follows: <span id="cpf"></span>
Understood this part, I could see that you will have to create a variable to save the parameter and then insert it in the desired field
See the following code to insert the "name" and "birth" fields in the html I used in the previous example:
// Campos que você quer pegar e exibir na página
let nome = getParameterByName('nome');
document.querySelector("#nome").innerHTML += nome;
let nascimento = getParameterByName('nascimento');
document.querySelector("#nascimento").innerHTML += nascimento;
In this case, your url would need to be something like http://127.0.0.1/pagina2.html?nome=Fulano&nascimento=01/01/1990
to display the name and birth in the fields
If you want to add more fields, you will have to add more variables that save the parameters and more insertion blocks in html, like this example to insert Cpf in <span id="cpf"></span>
To insert the Cpf:
let cpf = getParameterByName('cpf');
document.querySelector("#cpf").innerHTML += cpf;
Remembering that to display Cpf, your url would need to be something like: http://127.0.0.1/pagina2.html?cpf=ExemploDeCPF
The following code is just a function to pick a parameter, could send the complete code of the script you are trying to implement?
– JassRiver
The other part is an HTML, where there is a <form action="destination.html" method="GET>". The form that this script belongs to has only one field. I am trying to adapt it in another that has 16. I already increased the number of "var Sn" but I was not successful.
– jairo olindino
It would be easier to use php or json, but since you chose javascrip, it would not be better to use ajax/jquery to do this upload?
– Macedo_Montalvão