JavaScript error - - please help!

Q

questionr

There is a spell checker function which is written in VB Script. The
function works well when tested seperately. But when the function is
called from Java Script, the function shows an Error saying " A run
time error has occured. Do you wish to debug? Line :0 , Object
Expected". I just know that it is a Java Script error.
Any suggestions on how to resolve this problem ? What could be the
possible reasons for this error message?



Here is the spell checker function: The way this function is called
from JavaScript is like this :

<span style="float:right;text-align:right;width:50%"><a
href="javascript:SpellCheck(frmMain.taComment.innerText)">Spelling
Checker</a></span>

<%
function SpellCheck(strComments)
dim msg
dim objWord, objDocument, NumberofWords, NumberofErrors
Set objWord = CreateObject("Word.Application")
Set objDocument = objWord.Documents.Add
objDocument.Content = strComments

NumberOfWords = objDocument.Words.count
NumberOfErrors = objDocument.SpellingErrors.Count

If NumberOfErrors = 0 Then
Response.Write "No Spelling Errors" & "<br>"
'NO spelling errors...
Else
'loop through each word in the document
i=1
while i < NumberOfWords
if objDocument.Words(i).SpellingErrors.Count > 0 then
msg = "Misspelled: " & objDocument.Words(i).text & vblf &
"<br>"
'Yes, there are errors, see if there are any suggestions
for xSuggestions = 1 to
objDocument.Words(i).GetSpellingSuggestions.count
if xSuggestions = 1 then
msg = msg & vblf & "Suggestions: " &
objDocument.Words(i).GetSpellingSuggestions.Item(1).Name
else
msg = msg & vblf & " " &
objDocument.Words(i).GetSpellingSuggestions.Item(xSuggestions).Name
end if
next
Response.Write msg
else
end if
i = i + 1
wend
end If
objDocument.saveas "c:\t.doc"
objDocument.close false
set objDocument = nothing
objWord.quit false
Response.Write "Spell check is finished!"
end function
%>
 
G

Grant Wagner

questionr said:
There is a spell checker function which is written in VB Script. The
function works well when tested seperately. But when the function is
called from Java Script, the function shows an Error saying " A run
time error has occured. Do you wish to debug? Line :0 , Object
Expected". I just know that it is a Java Script error.
Any suggestions on how to resolve this problem ? What could be the
possible reasons for this error message?

Here is the spell checker function: The way this function is called
from JavaScript is like this :

<span style="float:right;text-align:right;width:50%"><a
href="javascript:SpellCheck(frmMain.taComment.innerText)">Spelling
Checker</a></span>

<%
function SpellCheck(strComments)
dim msg
dim objWord, objDocument, NumberofWords, NumberofErrors
Set objWord = CreateObject("Word.Application")
Set objDocument = objWord.Documents.Add
objDocument.Content = strComments

NumberOfWords = objDocument.Words.count
NumberOfErrors = objDocument.SpellingErrors.Count

If NumberOfErrors = 0 Then
Response.Write "No Spelling Errors" & "<br>"
'NO spelling errors...
Else
'loop through each word in the document
i=1
while i < NumberOfWords
if objDocument.Words(i).SpellingErrors.Count > 0 then
msg = "Misspelled: " & objDocument.Words(i).text & vblf &
"<br>"
'Yes, there are errors, see if there are any suggestions
for xSuggestions = 1 to
objDocument.Words(i).GetSpellingSuggestions.count
if xSuggestions = 1 then
msg = msg & vblf & "Suggestions: " &
objDocument.Words(i).GetSpellingSuggestions.Item(1).Name
else
msg = msg & vblf & " " &
objDocument.Words(i).GetSpellingSuggestions.Item(xSuggestions).Name
end if
next
Response.Write msg
else
end if
i = i + 1
wend
end If
objDocument.saveas "c:\t.doc"
objDocument.close false
set objDocument = nothing
objWord.quit false
Response.Write "Spell check is finished!"
end function
%>

You are trying to call a function defined on the server from client-side
JavaScript. This of course, will not work. When a request for this page
arrives at your server, IIS loads the .asp page, parses and executes
anything between <% and %> and sends the resulting *HTML* (and possibly
client-side JavaScript) to your client.

Once the document is at the client, the only thing client-side
JavaScript has access to is client-side code. As far as the server is
concerned, the client is gone, done, finished. The server-side code has
been parsed, executed and the result returned to the client, that
function is simply not available to client-side JavaScript (although it
would be available to code that might need it while that page is being
executed by IIS).

There are a variety of ways of calling server-side code from the client,
but given the fact that you haven't yet grasped the concept of
server/client separation, it would probably be fairly confusing to bring
them up and how they could be used to implement a client-side
spellchecker.

--
| Grant Wagner <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Turtle program error. Please help! 1
Code help please 4
I dont get this. Please help me!! 2
Help me with this task, please. 3
Please, help me. 1
Help Needed with VBA please help 0
Need help again please 19
Help :( 3

Members online

No members online now.

Forum statistics

Threads
473,787
Messages
2,569,630
Members
45,338
Latest member
41Pearline46

Latest Threads

Top