Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!--
Read the tutorial at 
http://programming-steps.blogspot.com/2016/10/google-sheet-data-crud-app-script-jquery.html
-->
<script  data-cfasync="false" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<form id="formCreate" >
    <h3>Create Record</h3>
    <p><label for="name">Name:</label>
    <input id="name" name="name" type="text" value="" /></p>
    <p><label for="comment">Comment:</label><br/>
    <textarea id="comment" name="comment" cols="40"></textarea></p>
    <input type="hidden" name="action" value="create">
    <p id="result"></p>
    <input type="submit" value="Create" />
</form>
<hr/>
<form id="formRetrieve" >
  <h3>Retrieve Records</h3>
    <input type="hidden" name="action" value="retrieve">  
    <input id="btnRetrieve" type="submit" value="Retrieve" />
  </form>
<br/>
<table id="datatable" border='1'>
</table>
  <div id="messageRetrieve"></div>
<hr/>
<form id="formUpdate" >
    <h3>Update Record</h3>
    <p><label for="tid">TID:</label>
    <input id="tid" name="tid" type="text" value="" disabled="true"/></p>  
    <p><label for="name">Name:</label>
    <input id="name" name="name" type="text" value="" /></p>
    <p><label for="comment">Comment:</label><br/>
    <textarea id="comment" name="comment" cols="40"></textarea></p>
    <input type="hidden" name="action" value="update">
    <input type="submit" value="Update" />
    <p id="messageUpdate"></p>
</form>
<hr/>
<form id="formDelete" >
      <h3>Delete Record</h3>
      <p><label for="dtid">TID:</label>
    <input id="dtid" name="tid" type="text" value="" disabled="true"/></p>  
    <p><label for="dname">Name:</label>
    <input id="dname" name="name" type="text" value="" disabled="true"/></p>  
    <input type="hidden" name="action" value="delete">
    <input type="submit" value="Delete" />
    <p id="messageDelete"></p>  
</form>



              
            
!

CSS

              
                
              
            
!

JS

              
                jQuery( document ).ready(function( $ ) {
	// variable to hold request
	var request;
	// bind to the submit event of our form
	   $("#formCreate").submit(function(event){
        // abort any pending request
        if (request) {
            request.abort();
        }
        // setup some local variables
        var $form = $(this);
        // let's select and cache all the fields
        var $inputs = $form.find("input, select, button, textarea");
        // serialize the data in the form
        var serializedData = $form.serialize();
    
        // let's disable the inputs for the duration of the ajax request
        // Note: we disable elements AFTER the form data has been serialized.
        // Disabled form elements will not be serialized.
        $inputs.prop("disabled", true);
        $('#result').text('Sending data...');
    
        // fire off the request to /form.php
        request = $.ajax({
            url: "https://script.google.com/macros/s/AKfycbwODToMRUJLIXoZF7RUVFf8v8KXKjZVx51URbsoj-P-oSGbhMk/exec",
            type: "post",
            data: serializedData
        });
    
        // callback handler that will be called on success
        request.done(function (response, textStatus, jqXHR){
            // log a message to the console
            $('#result').html('<a href="https://docs.google.com/spreadsheets/d/1PIJYBTjol_tEBuJMk5YvTRiePzqkdLMlRaZsEpC_ljg?usp=sharing" target="_blank">Success - see Google Sheet</a>');
      console.log("Created.");
      //console.log(response);
      //console.log(textStatus);
      //console.log(jqXHR);
      resetForm(); 
      $("#btnRetrieve").click();
        });
    
        // callback handler that will be called on failure
        request.fail(function (jqXHR, textStatus, errorThrown){
            // log the error to the console
            console.error(
                "The following error occured: "+
                textStatus, errorThrown
            );
        });
    
        // callback handler that will be called regardless
        // if the request failed or succeeded
        request.always(function () {
            // reenable the inputs
            $inputs.prop("disabled", false);
        });
    
        // prevent default posting of form
        event.preventDefault();
    });
  
  
	   $("#formRetrieve").submit(function(event){
        // abort any pending request
        if (request) {
            request.abort();
        }
        // setup some local variables
        var $form = $(this);
        // let's select and cache all the fields
        var $inputs = $form.find("input, select, button, textarea");
        // serialize the data in the form
        var serializedData = $form.serialize();
    
        // let's disable the inputs for the duration of the ajax request
        // Note: we disable elements AFTER the form data has been serialized.
        // Disabled form elements will not be serialized.
        $inputs.prop("disabled", true);
        resetForm();
        $('#messageRetrieve').text('Requesting data...');
                 $('#datatable').text("");

    
        // fire off the request to /form.php
        request = $.ajax({
            url: "https://script.google.com/macros/s/AKfycbwODToMRUJLIXoZF7RUVFf8v8KXKjZVx51URbsoj-P-oSGbhMk/exec",
            type: "post",
            data: serializedData
        });
    
        // callback handler that will be called on success
        request.done(function (response, textStatus, jqXHR){
            // log a message to the console
            $('#result').html('<a href="https://docs.google.com/spreadsheets/d/1PIJYBTjol_tEBuJMk5YvTRiePzqkdLMlRaZsEpC_ljg?usp=sharing" target="_blank">Success - see Google Sheet</a>');
      console.log("Retrieved.");
      //console.log(response);
      //console.log(textStatus);
      //console.log(jqXHR);
      var data = response.values;
      //console.log(data);      

                   var trHTML ="";

    $.each(data, function (i, item) {
      var tdHTML="";     
      //prepare first two columns
      if (i==0){
        tdHTML= "<td>Delete</td><td>Edit</td>" + tdHTML;
        tdHTML=tdHTML.replace(/td>/gi,"th>");
      }else{
        tdHTML+= "<td><button onclick='recordDelete(this)' >delete</button></td>";
        tdHTML+= "<td><button onclick='recordEdit(this)' >edit</button></td>";
      }
      //prepare remaining columns
      for (j = 0; j < item.length; j++) { 
        tdHTML += "<td>" + item[j] + "</td>";
      }
      trHTML += "<tr>" + tdHTML + "</tr>";  
    }); //end each records

    //append records to table element
    $('#datatable').append(trHTML);
    //reset 
    $('#messageRetrieve').text('');
 $('#messageRetrieve')[0].scrollIntoView(false);
        });
    
        // callback handler that will be called on failure
        request.fail(function (jqXHR, textStatus, errorThrown){
            // log the error to the console
            console.error(
                "The following error occured: "+
                textStatus, errorThrown
            );
        });
    
        // callback handler that will be called regardless
        // if the request failed or succeeded
        request.always(function () {
            // reenable the inputs
            $inputs.prop("disabled", false);
        });
    
        // prevent default posting of form
        event.preventDefault();
    });

	   $("#formUpdate").submit(function(event){
        // abort any pending request
        if (request) {
            request.abort();
        }
        // setup some local variables
        var $form = $(this);
        // let's select and cache all the fields
        var $inputs = $form.find("input, select, button, textarea");
        // serialize the data in the form
        var serializedData = $form.serialize();
    
        // let's disable the inputs for the duration of the ajax request
        // Note: we disable elements AFTER the form data has been serialized.
        // Disabled form elements will not be serialized.
        $inputs.prop("disabled", true);
        resetForm();
        $('#messageUpdate').text('Updating data...');
    
        // fire off the request to /form.php
        request = $.ajax({
            url: "https://script.google.com/macros/s/AKfycbwODToMRUJLIXoZF7RUVFf8v8KXKjZVx51URbsoj-P-oSGbhMk/exec",
            type: "post",
            data: serializedData
        });
    
        // callback handler that will be called on success
        request.done(function (response, textStatus, jqXHR){
            // log a message to the console
            $('#result').html('<a href="https://docs.google.com/spreadsheets/d/1PIJYBTjol_tEBuJMk5YvTRiePzqkdLMlRaZsEpC_ljg?usp=sharing" target="_blank">Success - see Google Sheet</a>');
      console.log("Updated.");
      //console.log(response);
      //console.log(textStatus);
      //console.log(jqXHR);
      resetForm(); 
      $('#messageUpdate').text('');
      $("#btnRetrieve").click(); 
        });
    
        // callback handler that will be called on failure
        request.fail(function (jqXHR, textStatus, errorThrown){
            // log the error to the console
            console.error(
                "The following error occured: "+
                textStatus, errorThrown
            );
        });
    
        // callback handler that will be called regardless
        // if the request failed or succeeded
        request.always(function () {
            // reenable the inputs
            $inputs.prop("disabled", false);
        });
    
        // prevent default posting of form
        event.preventDefault();
    });

  
	   $("#formDelete").submit(function(event){
        // abort any pending request
        if (request) {
            request.abort();
        }
        // setup some local variables
        var $form = $(this);
        // let's select and cache all the fields
        var $inputs = $form.find("input, select, button, textarea");
        // serialize the data in the form
        var serializedData = $form.serialize();
    
        // let's disable the inputs for the duration of the ajax request
        // Note: we disable elements AFTER the form data has been serialized.
        // Disabled form elements will not be serialized.
        $inputs.prop("disabled", true);
        resetForm();
        $('#messageDelete').text('Deleting data...');
    
        // fire off the request to /form.php
        request = $.ajax({
            url: "https://script.google.com/macros/s/AKfycbwODToMRUJLIXoZF7RUVFf8v8KXKjZVx51URbsoj-P-oSGbhMk/exec",
            type: "post",
            data: serializedData
        });
    
        // callback handler that will be called on success
        request.done(function (response, textStatus, jqXHR){
            // log a message to the console
            $('#result').html('<a href="https://docs.google.com/spreadsheets/d/1PIJYBTjol_tEBuJMk5YvTRiePzqkdLMlRaZsEpC_ljg?usp=sharing" target="_blank">Success - see Google Sheet</a>');
      console.log("Deleted.");
      console.log(response);
      console.log(textStatus);
      console.log(jqXHR);
      resetForm(); 
      $('#messageDelete').text('');
      $("#btnRetrieve").click(); 
        });
    
        // callback handler that will be called on failure
        request.fail(function (jqXHR, textStatus, errorThrown){
            // log the error to the console
            console.error(
                "The following error occured: "+
                textStatus, errorThrown
            );
        });
    
        // callback handler that will be called regardless
        // if the request failed or succeeded
        request.always(function () {
            // reenable the inputs
            $inputs.prop("disabled", false);
        });
    
        // prevent default posting of form
        event.preventDefault();
    });
  
  
  });

function recordEdit(param) {
resetForm();
var arrRecord=[];
$(param).closest('tr').find('td').not(':first').each(function() {
        //var textval = $(this).text(); 
       arrRecord.push( $(this).text());
   });
  $("#formUpdate #tid").val(arrRecord[1]);  
  $("#formUpdate #name").val(arrRecord[3]);
  $("#formUpdate #comment").val(arrRecord[4]);
  //window.location.hash = '#formUpdate';
        // var formUpdate = document.getElementById ("formUpdate");
        //formUpdate.scrollIntoView(true);
        $('#formUpdate')[0].scrollIntoView();
    //alert(address.join('\n'));
}; 

function recordDelete(param) {
resetForm();
var arrRecord=[];
$(param).closest('tr').find('td').not(':first').each(function() {
        //var textval = $(this).text(); 
       arrRecord.push( $(this).text());
   });
  $("#formDelete #dtid").val(arrRecord[1]);  
  $("#formDelete #dname").val(arrRecord[3]);
  //window.location.hash = '#formUpdate';
        // var formUpdate = document.getElementById ("formUpdate");
        //formUpdate.scrollIntoView(true);
        $('#formDelete')[0].scrollIntoView();
    //alert(address.join('\n'));
}; 

function resetForm(){
    $('#formCreate')[0].reset();
    $('#formUpdate')[0].reset();
    $("#formUpdate tid").prop("disabled", true);
    $('#formDelete')[0].reset(); 
    $("#formDelete dtid").prop("disabled", true);     $("#formUpdate dname").prop("disabled", true); 
}


              
            
!
999px

Console