Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get JS script of a Google form?

I owned a google form, how can I get the js script of it?

I click the Script Editor but there is no corresponding js I can find.

I have already searched on internet but no expected answers.

-- update on 20/08/2017

Assume that I owned a form like this : Sample Form.

How can I get the corresponding google script of this form?

i.e.,

function myFunction() {
    // Create a new form, then add a checkbox question, a multiple choice question,
    // a page break, then a date question and a grid of questions.
    var form = FormApp.create('Sample Form');
    var sect1 = form.addSectionHeaderItem();
    var item = form.addCheckboxItem();
    item.setTitle('What condiments would you like on your hot dog?');
    item.setChoices([item.createChoice('Ketchup'), item.createChoice('Mustard'), item.createChoice('Relish')]);
    var item2 = form.addMultipleChoiceItem().setTitle('Do you prefer cats or dogs?');
    //    .setChoiceValues(['Cats','Dogs'])
    //    .showOtherOption(true);
    var sect2 = form.addSectionHeaderItem();
    form.addPageBreakItem().setTitle('Getting to know you');
    form.addDateItem().setTitle('When were you born?');
    var sect3 = form.addSectionHeaderItem();
    var break2 = form.addPageBreakItem().setTitle('Getting to know you 2');

    var choice1 = item2.createChoice('cat', FormApp.PageNavigationType.CONTINUE);
    var choice2 = item2.createChoice('dog', break2);
    item2.setChoices([choice1, choice2]);

    form.addGridItem().setTitle('Rate your interests').setRows(['Cars', 'Computers', 'Celebrities']).setColumns(['Boring', 'So-so', 'Interesting']);
    Logger.log('Published URL: ' + form.getPublishedUrl());
    Logger.log('Editor URL: ' + form.getEditUrl());
}
like image 589
Bowen Xu Avatar asked Jan 30 '23 19:01

Bowen Xu


2 Answers

Google Script Editor is a way that Google allows people to make their forms (and many other Google services) more flexible and customizable. You can even create Add-ons using Google Scripts. But there is not such thing as a default user script for each form; all forms begin with no user Google Scripts at all and it is up to you to add some more functionality by writing some new scripts.

Now, if you mean to get the javascript source of that form, then you can use Developer Tools in Chrome (F12 key in Windows) and go to sources, there you'll see all the cripts that Google uses for the forms:

Google Forms JS

And if you left click the form and view the source of it, you'll see some more small script blocks mostly related to the data that the Google Form has:

<script>_docs_flag_initialData={ ....
<script>;this.gbar_={CONFIG:[[[0,"www.gstatic.com", ....
<script type="text/javascript">var FB_PUBLIC_LOAD_DATA_ = [null,[null, ....
like image 157
Christos Lytras Avatar answered Feb 03 '23 07:02

Christos Lytras


Another approach can be to create a html form yourself and send a request to a Google Apps Script Web app. See this example if you want to try it out: https://gist.github.com/mhawksey/1276293

Regards, Peter

like image 40
p3sn Avatar answered Feb 03 '23 06:02

p3sn