Click here to Skip to main content
12,757,882 members (33,128 online)
Click here to Skip to main content
Add your own
alternative version

Stats

90.5K views
1.6K downloads
27 bookmarked
Posted 30 Jun 2004

Spell check text area

, 17 Jul 2004
Rate this:
Please Sign up or sign in to vote.
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.

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:

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.

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.

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.

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.

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.

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

Share

About the Author

Vasanth Kumararajan
Web Developer
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
Questioncan this be a web application Pin
Member 1013584514-Jul-13 20:02
memberMember 1013584514-Jul-13 20:02 
AnswerRe: can this be a web application Pin
Vasanth Kumararajan11-Sep-13 2:35
memberVasanth Kumararajan11-Sep-13 2:35 
Questionspell check in a given text area in a web application Pin
kanupriya_tl22-Apr-08 21:49
memberkanupriya_tl22-Apr-08 21:49 
GeneralRe: spell check in a given text area in a web application Pin
kanupriya_tl24-Apr-08 20:22
memberkanupriya_tl24-Apr-08 20:22 
GeneralRe: spell check in a given text area in a web application Pin
Vasantha Mohan27-Apr-08 23:08
memberVasantha Mohan27-Apr-08 23:08 
QuestionHow can I use this spell script Pin
michaelmullan27-Sep-05 10:20
membermichaelmullan27-Sep-05 10:20 
AnswerRe: How can I use this spell script Pin
Vasantha Mohan1-Nov-07 7:52
memberVasantha Mohan1-Nov-07 7:52 
GeneralA little more information, please Pin
mav.northwind4-Jul-04 23:13
membermav.northwind4-Jul-04 23:13 
GeneralRe: A little more information, please Pin
S.K Vasantha Mohan18-Jul-04 13:19
memberS.K Vasantha Mohan18-Jul-04 13: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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 18 Jul 2004
Article Copyright 2004 by Vasanth Kumararajan
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid