0% found this document useful (0 votes)
4 views2 pages

Index HTML

The document contains a JavaScript code that utilizes jQuery and Bootstrap to manage form submissions and data retrieval from a Google Sheet. It includes functions for creating a country dropdown, handling form submissions, deleting and editing records, and displaying data in a table format. Additionally, it features a modal for loading indicators and error messages when data is not found.

Uploaded by

master_551993844
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Index HTML

The document contains a JavaScript code that utilizes jQuery and Bootstrap to manage form submissions and data retrieval from a Google Sheet. It includes functions for creating a country dropdown, handling form submissions, deleting and editing records, and displaying data in a table format. Additionally, it features a modal for loading indicators and error messages when data is not found.

Uploaded by

master_551993844
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

<script src="[Link]

js"></script><script
src="[Link]
[Link]" integrity="sha384-
ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe"
crossorigin="anonymous"></script> <script> // Prevent forms from submitting.
function preventFormSubmit() { var forms = [Link]('form'); for
(var i = 0; i < [Link]; i++) { forms[i].addEventListener('submit',
function(event) { [Link](); }); } } [Link]("load",
functionInit, true); //INITIALIZE FUNCTIONS ONLOAD function functionInit(){ $
('#spinnerModal').modal('show'); preventFormSubmit(); getLastTenRows();
createCountryDropdown(); }; //RETRIVE DATA FROM GOOGLE SHEET FOR COUNTRY DROPDOWN
function createCountryDropdown()
{ [Link](countryDropDown).getCountryList(); }
//POPULATE COUNTRY DROPDOWNS function countryDropDown(values) { //Ref:
[Link] var list =
[Link]('countryOfOrigin'); for (var i = 0; i < [Link]; i++)
{ var option = [Link]("option"); [Link] = values[i];
[Link] = values[i]; [Link](option); } } //HANDLE FORM SUBMISSION
function handleFormSubmit(formObject) { $('#spinnerModal').modal('show');
[Link](createTable).processForm(formObject);
[Link]("ProductDetails").reset(); } function deleteRecord(el)
{ var result = confirm("Want to delete?"); if (result) { $
('#spinnerModal').modal('show'); var recordId =
[Link][2].innerHTML;
[Link](createTable).deleteRecord(recordId);
[Link]("ProductDetails").reset(); } } //GET LAST 10 ROWS function
getLastTenRows ()
{ [Link](createTable).getLastTenRecords(); } function
editRecord(el){ $('#spinnerModal').modal('show'); let id =
[Link][2].innerHTML;
[Link](populateForm).getRecordById(id); } function
populateForm(data){ $('#spinnerModal').modal('hide');
[Link]('recId').value = data[0][0];
[Link]('name').value = data[0][1];
[Link]('description').value = data[0][2];
[Link]('category').value = data[0][3];
[Link]('countryOfOrigin').value = data[0][4];
[Link](data[0][5]).checked = true;
[Link]('price').value = data[0][6];
[Link]('quantity').value = data[0][7];
[Link]("message").innerHTML = "<div class='alert alert-warning'
role='alert'>Update Record [ID: "+data[0][0]+"]</div>"; } //CREATE THE DATA TABLE
function createTable(dataArray) { $('#spinnerModal').modal('hide'); if (dataArray
&& [Link]) { var result = "<table class='table table-sm' style='font-
size:0.8em'>" + "<thead style='white-space: nowrap'>" + "<tr>" + "<th
scope='col'>Delete</th>" + "<th scope='col'>Edit</th>" + "<th scope='col'
style='display:none;'>ID</th>" + // Hide the ID column header "<th
scope='col'>Product Name</th>" + "<th scope='col'
style='display:none;'>Description</th>" + "<th scope='col'>Category</th>" + "<th
scope='col'>Country of Origin</th>" + "<th scope='col'>Condition</th>" + "<th
scope='col'>Price</th>" + "<th scope='col'>Quantity</th>" + "<th scope='col'>Last
Update</th>" + "</tr>" + "</thead>"; for (var i = 0; i < [Link]; i++)
{ result += "<tr>"; result += "<td><button type='button' class='btn btn-danger btn-
custom deleteBtn' onclick='deleteRecord(this);'>Delete</button></td>"; result +=
"<td><button type='button' class='btn btn-warning btn-custom editBtn'
onclick='editRecord(this);'>Edit</button></td>"; for (var j = 0; j <
dataArray[i].length; j++) { if (j === 0) { result += "<td style='display:none;'>" +
dataArray[i][j] + "</td>"; // Hide the ID column data }else if(j === 2){ result +=
"<td style='display:none;'>" + dataArray[i][j] + "</td>"; // Hide the Description
column data } else { result += "<td>" + dataArray[i][j] + "</td>"; } } result +=
"</tr>"; } result += "</table>"; var div = [Link]("dataTable");
[Link] = result; [Link]("message").innerHTML = ""; } else {
var div = [Link]("dataTable"); [Link] = "Data not
found!"; }} //SEARCH RECORDSfunction handleSearchForm(formObject) { $
('#spinnerModal').modal('show');
[Link](createTable).searchRecords(formObject);
[Link]("search-form").reset();} function getAllRecords(){ $
('#spinnerModal').modal('show');
[Link](createTable).getAllRecords(); }</script>

You might also like