Search This Blog

Latest Blog Posts

Upload Image to Google Drive And Google Sheet From HTML File Input Element | JavaScript | AppScript

Upload Image to Google Drive And Google Sheet From HTML File Input Element | JavaScript | AppScript

Hello, in today's video i'll be showing you how to upload image in Google drive and Google sheet From HTML File Input Element.

AppScript Code


let app = SpreadsheetApp.openByUrl("Your_Google_Sheet_URL");
let sheet = app.getSheetByName("Your_Google_Sheet_Name");
function doPost(e){
try{
  let obj = JSON.parse(e.postData.contents);
  let dcode = Utilities.base64Decode(obj.base64);
  let blob = Utilities.newBlob(dcode,obj.type,obj.name);
  let newFile = DriveApp.createFile(blob);
  let link = newFile.setSharing(DriveApp.Access.ANYONE_WITH_LINK,DriveApp.Permission.VIEW).getDownloadUrl();
  let lr = sheet.getLastRow();
  sheet.getRange(lr+1,1).setFormula(`=IMAGE("${link}")`);
  return ContentService.createTextOutput("image uploaded")
}catch(err){
  return ContentService.createTextOutput(err)
}

}

Html JavaScript Code


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<input type="file"accept="image/*">
<img src="" alt="">
<script>
    let url = "Api_Endpoint_Url";
    let file = document.querySelector("input");
    let img = document.querySelector("img");
    file.addEventListener('change',()=>{
        let fr = new FileReader();
        fr.addEventListener('loadend',()=>{
            let res = fr.result;
            img.src=res;
            let spt = res.split("base64,")[1];
            // console.log(spt);
            let obj = {
                base64:spt,
                type:file.files[0].type,
                name:file.files[0].name
            }
            fetch(url,{
                method:"POST",
                body:JSON.stringify(obj)
            })
            .then(r=>r.text())
            .then(data=>console.log(data))

        })
        fr.readAsDataURL(file.files[0])
    })
</script>
</body>
</html>

Convert HTML CSS to PDF with JavaScript | HTML to PDF

Convert HTML CSS to PDF with JavaScript | HTML to PDF Hello, in this video i will show you how to convert HTML, CSS to PDF using JavaScript and HTML2PDF.js library.

Source Code to Convert HTML to PDF


<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HTML to PDF</title>
    <style>
        .elem {
            background-color: darkCyan;
            color: white;
        }
    </style>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js" integrity="sha512-GsLlZN/3F2ErC5ifS5QtgpiJtWd43JWSuIgh7mbzZ8zBps+dvLusV+eNQATqgA/HdeKFVgA5v3S/cIrLF7QnIg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</head>

<body>
    <div class="elem">
        Lorem ipsum dolor sit amet consectetur adipisicing elit. Sequi illo cumque ea velit, earum explicabo commodi ipsa voluptatem quidem dolores laborum eaque itaque nihil at eveniet similique fugit enim consequuntur, officia nostrum nemo! Nam voluptate corporis
        error aut nobis repellendus illo pariatur accusantium non quas dolores nihil dignissimos quam quisquam natus nostrum nesciunt officia temporibus doloremque, dolor iste! Aspernatur ad ratione perspiciatis sequi consequuntur aut nulla itaque consequatur.
        Aliquam fugit distinctio debitis deleniti, nisi nemo eius a, facilis dolorem tempora iusto laboriosam dicta beatae. Nisi, quisquam. Ducimus facere rerum veniam, reprehenderit labore expedita! Amet fuga, quia dicta excepturi iusto cumque.
    </div>
    <button class="download">Download PDF</button>
    <script>
        let div = document.querySelector(".elem");
        let btn = document.querySelector(".download");
        btn.addEventListener('click', () => {
            html2pdf().from(div).save()
        })
    </script>
</body>

</html>

Create a Working Contact Form Using HTML - CSS - JavaScript And AppScript | HTML Form to Email

Create a Working Contact Form Using HTML - CSS - JavaScript And AppScript. Hello, in today's video i will show you how to create a working contact form using HTML, CSS, JavaScript and AppScript.

HTML, CSS , JavaScript Code


<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Contact Form</title>
    <style>
        form {
            width: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-direction: column;
        }
        
        form * {
            width: 100%;
            margin-top: 2px;
        }
    </style>
</head>

<body>
    <form>
        <h2>Contact Us</h2>
        <span class="message"></span>
        <input type="text" name="name" placeholder='Name..'>
        <input type="email" name="email" placeholder='Email..'>
        <textarea name="message" cols="30" rows="10" placeholder='Message..'></textarea>
        <input type="submit" class="submit">
    </form>
    <script>
        let url = "Api End point url";
        let form = document.querySelector("form");
        let submit = document.querySelector(".submit");
        let message = document.querySelector(".message");
        form.addEventListener('submit', (e) => {
            e.preventDefault();
            submit.value = "submitting.."
            fetch(url, {
                    method: "POST",
                    body: new FormData(form)
                })
                .then(res => res.text())
                .then(data => {
                    message.innerHTML = data;
                    submit.value = "submit"

                })
                .catch(err => {
                    message.innerHTML = err;
                    submit.value = "submit"
                })
        })
    </script>
</body>

</html>

AppsScript Code


let sheet = SpreadsheetApp.openByUrl("YOUR_SPREADSHEET_URL")
function doPost(e){
  MailApp.sendEmail("receipent email address",`${e.parameters.name} from new contact form!`,`${e.parameters.message}\n${e.parameters.email}`)
  return ContentService.createTextOutput("Message has been Sent!")
}

CRUD App Using HTML - CSS - JavaScript and IndexedDB API

CRUD App Using HTML - CSS - JavaScript and IndexedDB API

Hello, in today's video i will be showing you how to create simple CRUD App using HTML, CSS, and JavaScript.

HTML, CSS code

Save below html , css code in index.html file.


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CRUD App</title>
    <style>
        form {
            display: flex;
            align-items: center;
            justify-content: center;
            flex-direction: column;
        }
        
        form * {
            width: 50%;
            margin-top: 2px;
        }
        
        .update {
            display: none;
        }
        
        .up,
        .de {
            background-color: red;
            color: white;
            cursor: pointer;
        }
        
        td,
        th {
            border: 2px solid black;
        }
        
        h1 {
            text-align: center;
        }
        
        table {
            width: 100%;
        }
    </style>
</head>

<body>
    <h1>CRUD-APP</h1>
    <form>
        <input type="text" placeholder='Name'>
        <input type="email" placeholder='Email'>
        <input type="tel" placeholder='Phone'>
        <input type="text" placeholder='Address'>
        <button type="button" class="submit">Submit Data</button>
        <button type="button" class="update">Update Data</button>
    </form>
    <table>
        <thead>
            <tr>
                <th>Name</th>
                <th>Email</th>
                <th>Phone</th>
                <th>Address</th>
                <th>Update</th>
                <th>Delete</th>
            </tr>
        </thead>
        <tbody>

        </tbody>
    </table>
    <script src="./script.js"></script>
</body>

</html>

JavaScript Code

Save below code in script.js file.


const form = document.querySelector("form");
const submit = document.querySelector(".submit");
const updates = document.querySelector(".update");
const tbody = document.querySelector("table>tbody");

submit.addEventListener('click', () => {
    let idb = indexedDB.open('crud', 1)
    idb.onupgradeneeded = () => {
        let res = idb.result;
        res.createObjectStore('data', { autoIncrement: true })
    }
    idb.onsuccess = () => {
        let res = idb.result;
        let tx = res.transaction('data', 'readwrite')
        let store = tx.objectStore('data')
        store.put({
            name: form[0].value,
            email: form[1].value,
            phone: form[2].value,
            address: form[3].value
        })
        alert("data has been added")
        location.reload()
    }
})

function read() {
    let idb = indexedDB.open('crud', 1)
    idb.onsuccess = () => {
        let res = idb.result;
        let tx = res.transaction('data', 'readonly')
        let store = tx.objectStore('data')
        let cursor = store.openCursor()
        cursor.onsuccess = () => {
            let curRes = cursor.result;
            if (curRes) {
                console.log(curRes.value.name);
                tbody.innerHTML += `
                
                ${curRes.value.name}
                ${curRes.value.email}
                ${curRes.value.phone}
                ${curRes.value.address}
                Update
                Delete
                
                `;
                curRes.continue()
            }

        }
    }
}

function del(e) {
    let idb = indexedDB.open('crud', 1)
    idb.onsuccess = () => {
        let res = idb.result;
        let tx = res.transaction('data', 'readwrite')
        let store = tx.objectStore('data')
        store.delete(e)
        alert("Data has been deleted")
        location.reload()
    }
}
let updateKey;

function update(e) {
    submit.style.display = "none";
    updates.style.display = "block";
    updateKey = e;
}
updates.addEventListener('click', () => {
    let idb = indexedDB.open('crud', 1)
    idb.onsuccess = () => {
        let res = idb.result;
        let tx = res.transaction('data', 'readwrite')
        let store = tx.objectStore('data')
        store.put({
            name: form[0].value,
            email: form[1].value,
            phone: form[2].value,
            address: form[3].value
        }, updateKey);
        alert("data has been updated")
        location.reload()
    }
})

read()

Reading Data From Google Sheet | Google Sheet to JSON and JSON to HTML | JavaScript and Apps Script

Reading Data From Google Sheet | Google Sheet to JSON and JSON to HTML | JavaScript and Apps Script

In today's video you will learn about How to read and display data from Google Sheet.

AppsScript Code


const ss = SpreadsheetApp.openByUrl("Your google sheet url")
const sheet = ss.getSheetByName("Sheet1")
function doGet(e){
  let obj = {};
  let data = sheet.getDataRange().getValues()
  obj.content = data;
return ContentService.createTextOutput(JSON.stringify(obj)).setMimeType(ContentService.MimeType.JSON)

}

Deploy your appsscript project and copy the API endpoint URL.

HTML, JavaScript Code


<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        tr {
            background-color: lightGrey;
        }
        
        tr:nth-child(2n) {
            background-color: grey;
        }
    </style>
</head>

<body>
    <table></table>
    <script>
        fetch('paste your api end point url here')
            .then(res => res.json())
            .then(data => {
                let tr = data.content.reduce((prev, cur) => {
                    let td = cur.map(e => `<td>${e}</td>`)
                    return prev + `<tr>${td.join("")}</tr>`
                }, "\r")
                document.querySelector("table").innerHTML = tr;
                
            });
    </script>
</body>

</html>

Keywords :

dynamically display data from google sheets into a web app
spreadsheet to html table
google html page
google apps script html table
spreadsheet in html
google apps script html css
google sheet to website free
google apps script html form submit
how to connect html form to google sheets
get data from google sheets to html
how to create a google page in html
google sheet page setup
how to create google search page in html

Contact Us