How to save button values using ajax to google sheet in java script

Viewed 23

Hi i have a HTML page containing 4 buttons giving 4 different outputs. I want to save the output from all of them in four different column.

This is what i have done so far

My google sheet

image

I want to save the values of output from four different button to four different columns. I tried but it is giving me an empty row as seen in the figure

My HTML code

            <i class="fa fa-forward">Next audio</i>
          </button>
          <button id="repeat" class="action-btn" name="repeat">
            <i class="fa fa-repeat">Repeat</i>
          </button>
          <br />
          <button id="yes" class="action-btn" name="yes">
            <i class="fa fa-yes">Yes</i>
          </button>

          <button id="no" class="action-btn" name="no">
            <i class="fa fa-no">No</i>
          </button>```

My ajax code for one button

$(document).ready(function () {
        $("#yes").click(function (e) {
          e.preventDefault();
          $.ajax({
            type: "POST",
            url: "https://script.google.com/macros/<somecode>/exec",
            data: $("#yes").val(),
            success: function (result) {
              alert("ok");
            },
            error: function (result) {
              alert("error");
            },
          });
        });
      });

0 Answers
Related