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

Accelerate Your Pipeline: Implementing Real-Time DataOps

Introduction Real-time DataOps is a critical evolution in how modern organizations manage the constant flow of information. By integrating automation, continuous testing, and real-time processing, businesses can…

Read More

Calculate Your Canada PR Points: The Complete Guide to Boosting Your CRS Score

Introduction Canada uses an objective, merit-based points system to select the most qualified candidates from around the world. To assess your chances, you need to use a…

Read More

Understanding Points Based Immigration System for Austria Red White Red Card

Introduction Austria offers an incredible mix of high-paying jobs, public safety, world-class healthcare, and a perfect work-life balance. It is no wonder that skilled professionals from all…

Read More

Automated Predictive Analytics Tools Driving Modern Agile DataOps Solutions

In the modern digital economy, reacting to problems after they happen is no longer enough. Businesses face an overwhelming flood of information every single day, making manual…

Read More

How DataOps and MLOps Work Together for Scalable AI Pipelines

Introduction In the current landscape of artificial intelligence, building a model is only the beginning. The real challenge for enterprise teams lies in the transition from a…

Read More

Evaluating Modern DataOps Tools Across Business Analytics Infrastructure

Introduction Managing data pipelines used to be a straightforward task for single analytics teams. Today, data ecosystems are complex, fast-moving, and frequently fragmented across multiple cloud environments….

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