By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,007 Members | 1,232 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,007 IT Pros & Developers. It's quick & easy.

spell checking use javascript to replace misspelled word from list?

P: n/a
I've got a spell checking function in php that will check the words in
a sentance and suggest corrections. Right now I have it to print out
the words with 6 suggestions for each misspelled word.

Ex: What is goiing (going,cooing,goring,geeing,goofing,goosing) on here
fellaws (fellas,fellows,fells,flaws,fellow's,fallows)
aroundd(around,aground,round,abound,ground,ironed) here

I want to be able to have the user click on the correct suggested word
and replace the misspelled word then once they are finished they will
resubmit the corrected string. Any ideas on how I can do this or a
better way to do this? You can see the example here by typing a
misspelled word in the keyword search box.


Feb 21 '06 #1
Share this Question
Share on Google+
2 Replies

P: n/a
Here's an example of doing this with a global variable (searchString).
You can presumably have your PHP script set that variable up when it
displays the list of misspelled words. The PHP script will also have
to add appropriate arguments to the replaceWord function call for each
word option that is displayed.

Not shown:
- dealing with multiword replacements
- onsubmit function that ensures the last value of searchString is
passed on to your search CGI script

Hope it helps,


<script language="javascript">
var searchString = 'bef caserole';
function replaceWord(pos, value)
var wordList = searchString.split(' ');
wordList[pos] = value;
searchString = wordList.join(' ');
alert('New searchString: ' + searchString);
return false;
<p>Did you mean:
bef (<a href="/" onclick="replaceWord(0,'beef'); return
<a href="/" onclick="replaceWord(0,'bf'); return false;">bf</a>,
<a href="/" onclick="replaceWord(0,'bed'); return false;">bed</a>,
<a href="/" onclick="replaceWord(0,'beg'); return false;">beg</a>,
<a href="/" onclick="replaceWord(0,'Be'); return false;">Be</a>,
<a href="/" onclick="replaceWord(0,'be'); return false;">be</a>)
caserole (<a href="/" onclick="replaceWord(1,'casserole'); return

Feb 21 '06 #2

P: n/a
Thanks John I'll try it out. I hope I can figure something out.
Appreciate the tip

Feb 21 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.