Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

304
Views
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 answers
Answer question

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 Report

0

This is how to autofill a form using HTML5.

<input value="valuehere">

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!