I am trying to add app script to google script but when I am writing the code some times it works and sometimes it gives error I can't find the error tell me what's wrong in this script

  <!--JavaScript at end of body for optimized loading-->
     <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
     <script>


    var nameBox = document.getElementById("Username");
    var phoneBox = document.getElementById("tel");

    document.getElementById("btn").addEventListener("click",addRecord);
    function addRecord(){

    var name = nameBox.value;
    var phone = phoneBox.value;
    if(name.trim().length == 0 || phone.trim().length == 0){

    M.toast({html: 'Invalid Input, Try Again !'});

    }else{

       var data = {

        name: nameBox.value,
        phone: phoneBox.value

        };

      google.script.run.appendData(data);

        nameBox.value = "";
        phoneBox.value = "";

      }

    }

    </script>

0 Answers