contact us

I am a Tech Entrepreneur and Photographer who is passionate about great design, disruptive technology and alkaline lifestyle. On my page you can find information about my entrepreneurial ventures, photos I have captured and things I have learned about life along the way.

East London

+447411787917

Dev Blog

Capture URL parameters with Javascript

Richard Ozols

When working with HTML forms on your own website or forms hosted elsewhere you might want to be able to populate some of the inputs using URL parameters.

Here is a simple vanilla Javascript that you can add right after your form that will look at the URL parameters and update form input elements based on their name.

(function(){
  var vars = {}, hash;
  var href = decodeURIComponent(window.location.href);
  var hashes = href.slice(window.location.href.indexOf('?') + 1).split('&');
  for(var i = 0; i < hashes.length; i++)
  {
      hash = hashes[i].split('=');
      var form_field = document.getElementsByName(hash[0]);
      if (form_field[0]) {
        form_field[0].value = hash[1];
      };
  }
})();

If you are looking for mobile forms or online surveys, please check out Formyoula.com