Tuesday, 4 November 2014

Module Chooser Using Javascript AND Apps Script

I had hoped that there might be a new Google Forms Add-on to do this, but no. I guess I'll have to have a go at doing it myself later.

Imagine you want your students to make a choice of four modules from a list of modules you're offering. To make the form easier to "not get wrong" it'd be good if when you chose module one, it disappeared from the following form items...

... like this.

The above is a hosted HTML on Google Drive ( because the Caja sanitation, or Chrome killed my Javascript ).

When a student chooses their preferred modules, the form is submitted to a regular doPost() method in a Google Spreadsheet's Apps Script like this...

function doPost(e) {
  Logger.log("Hi there")
    //Get values from form
    var email = Session.getActiveUser().getEmail()
    var module_one = e.parameter.module_one
    var module_two= e.parameter.module_two
    var module_three = e.parameter.module_three
    var module_four = e.parameter.module_four
    add_students_selection(email,module_one,module_two,module_three,module_four )
    var template = HtmlService.createTemplateFromFile('thank_you.html')
    template.this_url = ScriptApp.getService().getUrl( )
    return template.evaluate().setTitle("Thank You").setSandboxMode(HtmlService.SandboxMode.EMULATED)
    var template = HtmlService.createTemplateFromFile('error.html');
    template.this_url = ScriptApp.getService().getUrl( );
    template.error_title = e
    template.error_detail = e.stack
    return template.evaluate().setTitle("Error").setSandboxMode(HtmlService.SandboxMode.EMULATED)