0

Preface: Total noob here.

So I'm trying to create a page where:

  1. Provide a form where a user can enter a phone no.
  2. Check if the number is in pre-filled sheet (Google sheets), and if it has a corresponding message matched to it.
  3. Display message depending if there is a match; display generic rejection message if no match or number.

HTML:

    <form id="signup-form" method="post" action="#">
    <input type="tel" name="tel" id="phone" placeholder="eg. 123456789" />
    <input type="submit" value="Receive message" />
</form>

JS:

(function() {

"use strict";

(function() {


    var $form = document.querySelectorAll('#signup-form')[0],
        $submit = document.querySelectorAll('#signup-form input[type="submit"]')[0],
        $message;

    if (!('addEventListener' in $form))
        return;

    $message = document.createElement('span');
    $message.classList.add('message');
    $form.appendChild($message);

    $message._show = function(type, text) {

        $message.innerHTML = text;
        $message.classList.add(type);
        $message.classList.add('visible');
    };

    $message._hide = function() {
        $message.classList.remove('visible');
    };

    $form.addEventListener('submit', function(event) {

        event.stopPropagation();
        event.preventDefault();

        $message._hide();

        $submit.disabled = true;

        window.setTimeout(function() {

            $form.reset();

            $submit.disabled = false;

            $message._show('success', 'Have a nice day.');


        }, 750);

    });

})();

})();

I've been trying for the past 3 days, and I know I'm probably missing on quite a lot of stuff here- How can we make this functional?

rossoleone
  • 11
  • 1
  • 3

1 Answers1

0

I think you should check it out.

https://developers.google.com/apps-script/guides/sheets

How can I access Google Sheet spreadsheets only with Javascript?

Community
  • 1
  • 1
Emre Gozel
  • 45
  • 2
  • 7
  • Whilst this may theoretically answer the question, [it would be preferable](//meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Rory McCrossan Mar 27 '17 at 18:18