I have multiple textboxes that need spelled checked, I placed a WebSpellChecker control on the page for each text box, but when I click the button the dialog flashes a few times, and i only see the text for the last text box being checked....and it disapears....can't fix any errors.
How can I do this?
Also, is there a way to know that the spell check has been completed so that I can display a save button only after the spellcheck has been run?
So, how about this approach:
1. when you click your "Check Spelling" button, collect the content of the various textboxes, etc into an xml string that looks like this:
<ControlsToCheck>
<IDofControl1>contents of textbox 1</IDofControl1>
<IDofControl2>contents of textbox 1</IDofControl2>
...
</ControlsToCheck>
2. In your WebSpellChecker, set AllowXML to true. Then, using the spellchecker object:
oWebSpellChecker.checkSpelling(xml string from above)
3. In the completion callback, crack the xml using Microsoft.XMLDOM ActiveXObject (see also http://msdn2.microsoft.com/en-us/library/aa468547.aspx), loadXML method.
4. Go through the name/value pairs, and for each one, get the control (i.e., textbox) whose ID is the "name", and set its text to the "value" (i.e., the corrected text).
This allows you to
1. check multiple controls with just one invocation of the spell check dialog
2. only create one annoying flash if the text was spelled correctly in the first place, instead of one for every control
3. hit "ignore all" and have it really ignore all, instead of having to do this once per control.
It's a little tricky, but works pretty well.
-Scott
Hi All,
I have a question regarding this:
I'm using the method described to spell check multiple fields. I have a "checkspelling()" method in Javascript which is called when the user clicks the spell checker button. This method loads my form data in to XML:
storeXML +=
"<Field index=\"" + i.toString() + "\">";storeXML += xmlEscape(form_textboxes[i].value);storeXML += " </Field>";
I use a function called "xmlEscape" to encode illegal character such as "<" or "&". This is working well and the data appears correctly in the spell checker dialog. When the spell check is complete I am handling the "SpellCheckComplete" event with another method.
The problem I have is that the data that is coming back from the spell checker dialog has not been escaped and the method is failing:
WebSpellChecker_SpellCheckComplete(oWebSpellChecker, oEvent, uncheckedText, checkedText) {
var oXml = new ActiveXObject("Microsoft.XMLDOM");
//checkedText is not escaped so this line fails oXml.loadXML(checkedText);
So for exampe. Entering this text in a text box:
<< >>> && ""Will produce this input in checkSpelling():
<Field index='1'><< >>> && ""</Field>
But this argument is passed to SpellCheckComplete():
<Field index='1'><< >>> && ""</Field>
Which crashes the script as the xml cannot be parsed. Does anyone know of a solution?
Thanks,
P.S. apologies for the dodgy formatting of this post. I couldn't figure out how to set the fonts