10

I have a form made on google docs, and I have a script that I've just created (that isn't complete) that will analyze the responses on the form, and validate them based on info from a different google doc. Through trial and error I have figured out the id's for all of the elements on said form. I used:

var body = ""
var bodyTitle = ""


for (var i = 1; i < its.length; i ++)
{
    body = body + "  " +its[i].getId()
    bodyTitle = bodyTitle + "   " + its[i].getTitle()
}

and then by logging that out and basically just counting, the 5th id matches the 5th title, I have all of the id's. I'm just wondering for next time, is there a way I can look at the form and find it'd ID without doing this?

With HTML forms (I use chrome fyi) you can right click, inspect element, and you can see the id for page elements, and refer to them by that id in javascript. Is there a way to do this in Google Forms? that way I don't have to screw with just logging out all the id's and titles and matching them up.

Keep in mind: these are all forms created in Google Forms by users, they insist on making them. None of them are code made so I haven't been able to code the id's myself.

Rubén
  • 34,714
  • 9
  • 70
  • 166
user1759942
  • 1,322
  • 4
  • 14
  • 33

3 Answers3

27

Something like this will show you the ids in the logger... Open the form edit menu, load the script editor, paste the below inside a function and run it.

var form = FormApp.getActiveForm();
var items = form.getItems();
for (var i in items) { 
  Logger.log(items[i].getTitle() + ': ' + items[i].getId());
}
 

To see the IDs manually in Chrome >> View Form >> right-click on the question Label >> Inspect element >> look for the for="entry_XXXXXXX" attribute. That 'xxxxxxx' will be the id.

Miltos
  • 23
  • 5
Bryan P
  • 5,031
  • 3
  • 30
  • 44
  • that's exactly what I put that I already did. `for (var i = 1; i < its.length; i ++) { body = body + " " +its[i].getId() bodyTitle = bodyTitle + " " + its[i].getTitle() }` see? all I left out was the logger statement. I dont want to do that though.. is there a way I can see the id without doing that? – user1759942 Mar 06 '14 at 14:16
  • edited answer for the attribute to look for. that way? – Bryan P Mar 06 '14 at 19:57
  • yes that way.. but unfortunately it doesnt work :( I looked through the source and none of the id's in my log were found in the source at all. – user1759942 Mar 06 '14 at 20:13
  • but you do see ids in the source? you have to inspect the actual Form and not the Form Editor. Also, I noticed logging the ids by themselves ( `Logger.log(its[i].getId()` ) returns the id in a different format than what's shown in the souce. – Bryan P Mar 06 '14 at 20:34
  • I did copy and paste your code and use that, I get the same Id's as the other ones except for one of them (which is weird) but i was viewing source for the live form and the id's there are totally different. If i view the id's when editting, I just found now that those are the ones I need. But I can only see some of them.. like for check boxes I can see the id's but not for textboxes – user1759942 Mar 06 '14 at 21:22
  • do you know why they are logged in a different format when I do that? – user1759942 Mar 06 '14 at 21:22
  • I found them all. I had to use IE and view source. in chrome I`d been clicking on the actual check boxes or textboxes, you have to click where the question name would be. most of the questions on the form my user made dont have names! so in IE i took the id i saw in the logs and did a ctrl+F and found one one of them, then copied the tag names, and I found those tag names in chrome. had to expand a few extra things to find them. they are in `Label` tags. Thanks much! that'll make thigns so much easier for scripting now! :D – user1759942 Mar 06 '14 at 21:38
4

2021 update:

To find the ID manually:

  1. Inspect question element
  2. Find [data-params] attribute
  3. The second number will be the right one

Example:

data-params="%.@.[860146445,"Question",null,0,[[305915825,[],true,[],[],null,null,null,null,null,[null,[]]]],null,null,null,[]],"i1","i2","i3",false]"

305915825 - this is the field ID that you can use like ?entry.305915825=<your-predefined-content>

Roman
  • 101
  • 2
  • 4
2

An update to Bryan P's answer:

To find the ID:

  • view the form (as if you were taking it)
  • right click and inspect the question name
  • look for either:
    • data-item-id="##########", or
    • aria-describedby="i.desc.########## i3"

You want the ##########.

Van
  • 302
  • 3
  • 18