How To Create a Spelling Check Website through javascript

Step 1:- Create a html page

<div class="container">
                     <h1>Spell Check Search</h1>
                     <br><br>
                     
                     
                        <textarea id="textarea" class="textarea" maxlength="150" placeholder="Type something here..." required></textarea>

                        <div class="counter-container">
                           <p> Total character: <span id="total-counter"> 0 </span></p>&nbsp;&nbsp;
                           <p> Remaining character: <span id="remaining-counter"> 150</span></p>
                        </div>
                        <div class="butonwa">
                           <button id="Button">Correct Text </button>
                           <!-- <button id="copy"> Copy Text</button> -->
                        </div>
                     

                     <!-- <ul id="synonymsList"></ul> -->
                  </div>

Step 2:- Add on html page

<script src="script.js"></script>

Step 3:- Create a script.js

const charVal = document.getElementById("textarea");
let totalcount = document.getElementById("total-counter");
let remainingcount = document.getElementById("remaining-counter");
const button= document.querySelector("#Button");
const copy=document.querySelector("#copy")

let userChar = 0;

const updateCounter = () => {
    totalcount.innerText = charVal.value.length;
    remainingcount.innerText = 150 - charVal.value.length;
};


                var textarea = document.getElementById("textarea");
        
                textarea.addEventListener("input", function() {
                  this.style.height = "60px";
                  this.style.height = (this.scrollHeight + 2) + "px";
                });
                

const copyText = async () => {
    charVal.select();
    charVal.setSelectionRange(0, 9999);
    navigator.clipboard.writeText(charVal.value);
}
const correctText = async ()=>{
    try {
        // send text to LanguageTool API for correction
        const response = await fetch("https://api.languagetool.org/v2/check", {
            method: "POST",
            headers: {
                "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
            },
            body: new URLSearchParams({
                text: charVal.value,
                language: "en-US",
                enabledOnly: "false"
            })
        });

        const data = await response.json();

        const correctedText = data.matches.reduce((text, match) => {
            const startIndex = match.offset;
            const endIndex = match.offset + match.length;
            const replacement = match.replacements[0].value;
            return text.slice(0, startIndex) + replacement + text.slice(endIndex);
        }, charVal.value);


        charVal.value = correctedText;
    } catch (error) {
        console.error(error);
    }
};



charVal.addEventListener("keyup", updateCounter);

copy.addEventListener("click", async () => {
    await copyText();
});

button.addEventListener("click", async () => {
    await correctText();
});

Search:-

Output:-

Add CSS what you want….

I hope it will help you … Happy Coding!!!!

Related Posts

Exploring Financial Operations Workflows in Modern Cloud Environments

Introduction The Certified FinOps Professional is the definitive benchmark for experts looking to master the intersection of finance, engineering, and business. As organizations transition from traditional data…

Read More

Strategic Certified FinOps Engineer integrates governance with cloud operations

Introduction The shift to cloud computing has fundamentally altered how businesses manage infrastructure, but it has also introduced significant financial complexities that many engineering teams struggle to…

Read More

Certified FinOps Manager Knowledge for Cloud Financial Governance

Introduction The shift toward cloud-native infrastructure has brought undeniable speed, but it has also introduced significant financial complexity. The Certified FinOps Manager is a professional designation designed…

Read More

Smart Career Growth Through Certified FinOps Architect Learning Journey

Introduction The Certified FinOps Architect is a professional certification designed to help engineers, cloud professionals, and managers optimize cloud financial operations and cost efficiency. This guide is…

Read More

CDOM – Certified DataOps Manager Learning Path for Modern Data Professionals

Introduction The CDOM – Certified DataOps Manager is a professional designation designed to bridge the gap between data engineering and operational excellence. This guide is written for…

Read More

Professional development journey using CDOA – Certified DataOps Architect

Introduction The CDOA – Certified DataOps Architect is a professional designation designed to address the unique challenges of managing and scaling data delivery in cloud-native environments. This…

Read More
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x