Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

308
Visualizações
Prefill form based on URL parameters javascript

I'm passing name & email through URL parameters from a popup form like this xyz.com?om_email=test%40test.com&om_name=Test

I need these two forms prefilled on xyz.com site

<p>
<input type="text" name="name">
<input type="email" name="email">
</p>

Can anyone please help?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

More context would be nice, but try this:

I used a test URL string to allow the example to work, but on the actual site, replace params variable with the one that is commented, (hint: window.location.search) to extract the parameters from the URL.

There are different ways to do this, but I created an object from the parameter string then looped over the inputs and updated their value by matching the data object key to the input value name attribute.

Note: Be sure to run the JavaScript after the page loads.

var url = "xyz.com?om_email=test%40test.com&om_name=Test";
var params = "om_email=test%40test.com&om_name=Test".split("&");
//use this on the actual site to extract parameters from the url
//var params = window.location.search.slice(1).split("&");
//convert the params to an object
var data = params.reduce((obj, param) => {
  var pair = param.split("=");
  return { ...obj,
    [pair[0].replace("om_", "")]: decodeURIComponent(pair[1])
  }
}, {});
//console.log({data});
//insert values by matching input name to data object key
document.querySelectorAll("input").forEach(input => input.value = data[input.name]);
<p>
  <input type="text" name="name">
  <input type="email" name="email">
</p>

about 4 years ago · Juan Pablo Isaza Relatório

0

This is how to autofill a form using HTML5.

<input value="valuehere">

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda