Skip to content

Instantly share code, notes, and snippets.

@caseywatts
Last active October 14, 2022 00:07
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save caseywatts/5952495 to your computer and use it in GitHub Desktop.
Save caseywatts/5952495 to your computer and use it in GitHub Desktop.
Easily fill out web forms using data from a spreadsheet using this bookmarklet.

Other gists & tricks: http://caseywatts.com/gists-and-tricks

To set this up, paste the code below into the "location" of a bookmark. Make sure it starts with "javascript:", some browsers strip this out when you paste.

  1. Find the "name" of each form element you want to put data into. You can find the "name" by right clicking on the form box and "inspecting" it.
  2. By using a spreadsheet, create a set of urls with the data you want to input. Example: variablename1 is the "name" of the form field. "value1" is the value you want to put into the box.www.website.com/page.html?variablename1=value1&variablename2=value23. Navigate to that custom URL4. Click the bookmarklet. Voila!
javascript: function getUrlVars() {
var vars = [],
hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
function ParamsIntoForms(get) {
for (var i = 0; i < get.length; i++) {
if (document.getElementsByName(get[i]).length != 0) {
document.getElementsByName(get[i])[0].value = decodeURIComponent(get[get[i]]);
}
}
return false;
}
var get = getUrlVars();
ParamsIntoForms(get);
@kibkib
Copy link

kibkib commented Feb 8, 2021

Thanks. This is useful.
It did not work for me when there were reserved characters in the element name.

! | # | $ | & | ' | ( | ) | * | + | , | / | : | ; | = | ? | @ | [ | ]
%21 | %23 | %24 | %26 | %27 | %28 | %29 | %2A | %2B | %2C | %2F | %3A | %3B | %3D | %3F | %40 | %5B | %5D

I had to change it like this:
....

            dcd=decodeURIComponent(get[i]);
            if (document.getElementsByName(dcd).length != 0) {
                document.getElementsByName(dcd)[0].value = decodeURIComponent(get[get[i]]);
               //also I fire an onchange event of the changed element as the form i need to fill requires it
                document.getElementsByName(dcd)[0].onchange();

            }
.
```...

@psthampi
Copy link

psthampi commented Feb 26, 2021

Thanks
For text fields like first name and last name and date of birth it works fine
Is there any extra code for radio buttons in this case for sex of patient.
example for male patient i tried
ctl00$cntHolder$PatientDemographics1$rdPatientSex=M
It does not work
Thanks
ss

Any advise?
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment