4

I am working on a form in Google Forms.

At some point during my form, I need to validate an answer based in a previous answer.

To make it more clear, I give you an example:

  1. How many hours do you work per day? 30
  2. How many of those hour do you use conference calls? 40

This should return an error. Because the answer in 2. must be equal or less than answer in 1.

Is there anyway of doing this kind of validation?

3
  • 1
    Possible duplicate of Apply custom CSS styles to Google Forms
    – Rubén
    May 1 '17 at 3:48
  • 1
    @Rubén Did you choose the wrong duplicate? I don't see the connection.
    – jonsca
    May 2 '17 at 1:44
  • @jonsca: The answer is the same, the new Google Forms haven't a built-in feature to add custom HTML/JavaScript/CSS.
    – Rubén
    May 2 '17 at 1:49
0

At this time Google Forms doesn't include a way to extend the form respondent view by any means including the use of custom HTML/CSS/JavaScript.

One alternative is to do the validation after the response was submitted by using Google Apps Script. This validation could log the validation result by changing a form response value, editing another file like a spreadsheet or online database.

A more radical alternative is to use other app to create your form like the Google Apps Script HTML Service, Google App Maker (but this only works for internal use of G Suite organizations), among other apps.

0

You can build the Google Form with a Google Script. I am not sure if that will work dynamically while the form is in use or if you have to set the range of values for number validation up front and they remain static once the form is created.

The following resource may come in handy: Class TextValidationBuilder Even if it says Text Validation, it refers to a short answer question type:

// Add a text item to a form and require it to be a number within a range.
var textItem = form.addTextItem().setTitle('Pick a number between 1 and 100?');
var textValidation = FormApp.createTextValidation()
  .setHelpText('Input was not a number between 1 and 100.')
  .requireNumberBetween(1, 100)
  .build();
textItem.setValidation(textValidation);

If the whole form is built via the script, you could potentially use the result of the previous question as the higher limit in the .requireNumberBetween statement above. Worth a try.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.