Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find id of element on already made google form?

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.

like image 436
user1759942 Avatar asked Mar 03 '14 14:03

user1759942


3 Answers

Something like this will show you the ids in the logger...

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.

like image 103
Bryan P Avatar answered Nov 03 '22 19:11

Bryan P


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>

like image 40
Roman Avatar answered Nov 03 '22 19:11

Roman


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 ##########.

like image 2
Van Avatar answered Nov 03 '22 17:11

Van