Discussion Locked

Spell Checking using JavaScript

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
How to spellcheck the text in the textarea available in the HTML using JavaScript?

7 replies

by jay eckles

You've got to store a dictionary in a Javascript object...this would probably have to be fairly large if it's going to be a useful spell checker...perhaps you could have an array and store it in an external .js file and include it with a script tag. It would still take a while for the user to download. Once you've got that, you'll have to create a method to split the value of the textarea into words...not too hard, then you'll have to figure out an algorithm for comparing the words to the words in the dictionary; you'll probably want to use some sorting methods to speed up the lookup of where the word would be in the dictionary, then compare it to the word in hand. Finally, you'll need to determine how you'll alert the user that the word is misspelled. If you want to give suggestions, that will be another challenge altogether, and if you want users to be able to "add" to the dictionary (ala Word), you'll have to do some server-side scripting to modify your external .js file.

It's doable, but I wouldn't call it trivial, and there are going to be a couple of significant obstacles to overcome.

Jay Eckles
www.jayeckles.com

by ebob

It wouldn't be easy. You would have to load some sort of dictionary onto the client (assuming client-side JS), which would take some bandwidth., then search each word of the text box across this dictionary. You may have to allow for "local" variants, too. For example, if you're serving to an English language audience on the WWW, then you would need to allow for the English and American spellings of words like "colour" and "organise" ("color" and "organize" in American). Then there's the possibility of having to deal with non-English languages, and characters.

In the end, you have to ask yourself if it's really worth it.

by tjc

As you can see by the previous posts you really wouldn't want to because of all the coding involved. An easier way to spellcheck would be to have when the submit the form spellcheck it using the unix/linux dictionary (that is if you are using one ofthose oses for a web host) though some perl or other cgi processing.

This discussion is closed to new replies.