Find id of element on already made google form?

帅比萌擦擦* 提交于 2019-12-29 05:00:09

问题


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.


回答1:


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.




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



来源:https://stackoverflow.com/questions/22149982/find-id-of-element-on-already-made-google-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!