Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

Spell check in web applications

Sam Ruby has enabled spell checking for the preview comment tool on his blog. I wonder how it works... I’ve lost track of the scripting language Sam uses for Intertwingly (PHP? Python? Perl?) but I know PHP can be compiled with support for the Pspell module.

Sam’s user interface is pretty neat—misspelled words are marked up with a span, underlined in dashed red and have suggested spellings listed in the span’s title attribute. Theoretically, it should be possible to build a javascript right-click menu offering alternatives instead (preferably dynamically generated from the list of words in the title attribute using the DOM). Actually modifying the preview textarea text based on the menu selection would be quite a lot harder—it could be done with a simple search-and-replace operation, but doing so might change other words with the same “incorrect” spelling without the user realising.

It would be fun to integrate something like this with a rich text editor, such as the recently announced htmlArea 3.0 that works with Mozilla 1.3b as well as IE (more information here).

This is Spell check in web applications by Simon Willison, posted on 8th March 2003.

View blog reactions

Next: WThRemix entrants

Previous: Jeff minter blogs

8 comments

  1. What if each misspelled word was indexed with an id, could you then search/replace on the span item with class spellcheck and id x ?

    Swannie - 8th March 2003 19:39 - #

  2. Not really, because the stuff you were searching and replacing on would be plain text in a textarea without any span tags in sight. I suppose you could leave the span tags in there and strip them once the user submitted the form, but that would look quite ugly from the user's point of view. Worth considering though.

    Simon Willison - 8th March 2003 23:16 - #

  3. Ah, but your Javascript menu should call a function as changeSpelling('misspeled','misspelled',32), which is (mispelledWord, corectSpelling, charsFromStartOfText).

    Stuart Langridge - 9th March 2003 00:10 - #

  4. Moreover, use the XML-RPC spellchecker at http://www.stuffeddog.com/speller/index.html, or possibly host a version on your own server...

    Stuart Langridge - 9th March 2003 00:11 - #

  5. Additional thought: having the right-click menu call a JS replacement function with a number-of-chars-from-start value will break if you ever replace a word with a longer or shorter word; subsequent replacements will have the wrong character values. I wonder what the best way around this is?

    Stuart Langridge - 9th March 2003 12:16 - #

  6. You could, of course, keep track of how many characters you were inserting or removing and then adjust your other values from this. Seems a bit messy, though.

    Lach - 10th March 2003 06:05 - #

  7. draf

    sdfsad - 9th December 2004 13:39 - #

  8. ghjgjgj hgjg

    hgj - 2nd September 2005 11:33 - #

Comments are closed.

Previously hosted at http://simon.incutio.com/archive/2003/03/08/spellCheckInWebApplications

A django site