Click here to Skip to main content
15,867,704 members
Articles / Web Development / IIS
Article

Spell check text area

Rate me:
Please Sign up or sign in to vote.
2.83/5 (6 votes)
17 Jul 20042 min read 106.9K   1.7K   27   9
Spell check text area.

Sample Image - spell_check.gif

Introduction

It's been always a dream for me to create this small web app. I have searched the web to find out only paid support for any web app related to spell check, except for this chap - Sam @ KIRCHMEIER.ORG who actually inspired me to develop this spell check, which would not only permit one word to be validated rather the entire paragraph.

Default Document Settings

If your IIS is not set to open index.asp as a Default Document, you would either have to type in the entire URL with ../index.asp or include it into the Default Document.

Database Users

If you alter this script to work with a database, there are a couple of things you should be aware of. Sort order is very important to this script; if the word lists are not sorted properly, the script will malfunction or not work at all. Sort order will vary among databases, and sometimes VBScript's string comparisons wont agree with the sort order that your database produces. For example, the words: standards, and standard's, might appear in a sorted result set in that order. But VBScript dictates that standard's < standards, so standard's must appear first in the word list to be found by the SpellCheck function.

UPDATED FOR MAV:

Blurb of what the code does:

  1. Break sentences with the famous MS office line breaker "¶".
  2. Check whether the user is not submitting a blank text field or not.
  3. Remove leading and trailing spaces from the passed string.
  4. Open a new window to post the altered text.
  5. Split the words into a virtual 3D array from the passed string.
  6. Parse the words to spell.asp.
  7. Spell.asp - Soundex function.
  8. Display the spell checked text.

Break sentences with the famous MS office line breaker "¶".

Whenever the user hits the return key, this chunk of string " ¶ " is appended to the text along with the line break.

JavaScript
function DisplayEvent()
{
 if (event.keyCode == 13)
 {
  myMessage  = window.document.F1.T1.value+" "+"¶"+" ";
  window.document.F1.T1.value=myMessage
 }
}

Check whether the user is not submitting a blank text field or not.

Validation is one mandatory point among the "Good Programming Techniques".

This code here verifies whether the text field is blank or not:

JavaScript
if (trim(document.F1.T1.value)=="")
{
 alert("Enter Text");
 document.F1.T1.focus();
 return false;
}

If it is blank, it stops further processing by alerting the user to enter text.

Remove leading and trailing spaces from the passed string.

Removes leading and trailing spaces from the passed string. Also removes consecutive spaces and replaces it with one space.

If something besides a string is passed in (null, custom object, etc.), then return the input.

JavaScript
function trim(inputString)
{
 if (typeof inputString != "string") { return inputString; }
 var retValue = inputString;
 var ch = retValue.substring(0, 1);
 while (ch == " ")
  { // Check for spaces at the beginning of the string
  retValue = retValue.substring(1, retValue.length);
  ch = retValue.substring(0, 1);
 }
 ch = retValue.substring(retValue.length-1, retValue.length);
 while (ch == " ")
 { // Check for spaces at the end of the string
  retValue = retValue.substring(0, retValue.length-1);
  ch = retValue.substring(retValue.length-1, retValue.length);
 }
 while (retValue.indexOf("  ") != -1)
 { 
 // Note that there are two spaces in the string
 // - look for multiple spaces within the string
  retValue = retValue.substring(0, 
    retValue.indexOf("  ")) + 
    retValue.substring(retValue.indexOf("  ")+1, 

 retValue.length);
 // Again, there are two spaces in each of the strings
 }
 return retValue; // Return the trimmed string back to the user
}

Open a new window to post the altered text.

JavaScript
val=window.document.F1.T1.value
var winl = (screen.width - w) /2; 
// Synchronize to the current screen resolution
var wint = (screen.height - h) / 2; 
// Synchronize to the current screen resolution
mypage="spellcheck.asp?T1="+val
winprops = 'height='+h+',width='+w+',
           top='+wint+',left='+winl+',
           scrollbars='+scroll+',resizable'
win = window.open(mypage, myname, winprops)
return false;

Split the words into a virtual 3D array from the passed string.

VBScript
a1 = Request("T1")
a1=Trim(a1)
a=split(a1," ") // Delimiter here is blank space

For i=0 to UBound(a)-1 
// Returns the largest available subscript
// for the indicated dimension of an array
 b=b++a(i+1)+" "
Next

Response.Cookies("myword")=b

Parse the words to spell.asp.

VBScript
if PrepForSpellCheck(strHaha) then 
// Validates whether the alrtered string has alpha variables only
 Response.Cookies("final")=Request.Cookies("final")+" "+strHaha
 Response.Redirect("spellcheck1.asp")
end if

Dim strHaha
Dim strWord

if a(0) & "" <> "" then
 LoadDictArray
 strHaha = a(0)

 if SpellCheck(strHaha) then
  Response.Cookies("final")=Request.Cookies("final")+" "+strHaha
  Response.Redirect("spellcheck1.asp")
 end if

 if IsNumeric(a(0)) then
  Session("final")=Session("final")+" "+a(0)
  Session("final")=Trim(Session("final"))
  Response.Redirect("spellcheck1.asp")
 end if

 k=1

 for each strWord in Suggest(strHaha)
  k=k+1
 next

 if k=1 then
  Response.Cookies("final")=Request.Cookies("final")+" "+a(0)
  Response.Redirect("spellcheck1.asp")
 end if

 if k>8 then
  k=6
 end if

Spell.asp - Soundex function.

I suggest you to refer to this site so that you can better understand about the Soundex function.

Display the spell checked text.

VBScript
a=Request.Cookies("final")
a=Replace(a,"¶","<br>") 
// Returns a string in which a specified
// substring (¶) has been replaced with
// another substring (<br>)
Response.Write a

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questioncan this be a web application Pin
Member 1013584514-Jul-13 19:02
Member 1013584514-Jul-13 19:02 
AnswerRe: can this be a web application Pin
Vasanth Kumararajan11-Sep-13 1:35
Vasanth Kumararajan11-Sep-13 1:35 
Questionspell check in a given text area in a web application Pin
kanupriya_tl22-Apr-08 20:49
kanupriya_tl22-Apr-08 20:49 
GeneralRe: spell check in a given text area in a web application Pin
kanupriya_tl24-Apr-08 19:22
kanupriya_tl24-Apr-08 19:22 
GeneralRe: spell check in a given text area in a web application Pin
Vasanth Kumararajan27-Apr-08 22:08
Vasanth Kumararajan27-Apr-08 22:08 
QuestionHow can I use this spell script Pin
michaelmullan27-Sep-05 9:20
michaelmullan27-Sep-05 9:20 
AnswerRe: How can I use this spell script Pin
Vasanth Kumararajan1-Nov-07 6:52
Vasanth Kumararajan1-Nov-07 6:52 
GeneralA little more information, please Pin
mav.northwind4-Jul-04 22:13
mav.northwind4-Jul-04 22:13 
GeneralRe: A little more information, please Pin
Vasanth Kumararajan18-Jul-04 12:19
Vasanth Kumararajan18-Jul-04 12:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.