---
url: /posts/2024/the-easy-way-preset-google-forms-field-ids.md
description: >-
  A very short post on how to get the field ids of a google form with a few
  lines of javascript
---

Getting the field ids of a google form is required to pre set certain fields with GET parameters. However, figuring out the ids of all different field types by inspecting, searching and guessing is a pain.

To overcome this, I wrote a small script that will print the field ids to the console next to the field label headlines, so there's no guessing involved.

Just paste the script into the developer console *in the preview or public view of your form*, hit enter and you're done.

```js
document.querySelectorAll('[data-params]').forEach(item => {
    const name = item.dataset.params?.match(/\[\[(\d+)/)?.[1];
    if (!name) { return false; }
    const node = document.createElement('code');
    node.innerText = `GET parameter: entry.${name}`;
    node.style.setProperty('margin', '1rem 0')
    item.querySelector('[role="heading"]')?.parentNode.appendChild(node);
})
```
