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
You could get around the need to escape those XML characters if you came up with an alternative 'syntax' for combining the strings into one. In other words, instead of using XML, and the XML classes to parse it, use some custom format with your own joining string and just use the javascript split method to parse it on completion.
It's not quite as nice as having the xml node as a single object with a value and text attributes (instead, every even element of the split array would be the ids of the controls, whilst the odd elements would be the text), but it would get around the need to show something that looks quite different to what the user entered when spell checking, and would allow you to customise what the joining string is, so that it could be even something "pretty" like:
============
so you are spellchecking this text:
field1============This text is in field 1 and it is not splet correctly.============field2============This text is in field 2 and is spelt correctly.You get the idea.
Update 2:
I've found a work-around for the time being. I'm encoding characters using my own, descriptive syntax and then unencoding them afterwards. So:
">" is replaced with "[greater than]"
"<" is replaced with "[less than]"
"&" is replaced with "[ampersand]"
Obviously the escaped value is appearing in the spell checker dialog but because the escaped string is verbose I don't think it is particularly confusing to the end user. The strings are unencoded again in the SpellCheckerComplete method.
Cheers,
Just an update:
I've tried using CDATA tags to encode the input. This works insofar that they are passed through and the XML remains valid in the SpellCheckComplete handler. The problem is that they show up in the spell checker dialog and also seem to be confusing it as sometimes it doesn't report obvious errors.
Anyone have any other ideas?