atwoodj
asked on
Javascript Clean MS Word characters - Safari problem
I'm using Javascript to clean up a textarea so that proprietary characters that MS Word likes to insert, such as Smart Quotes, are removed before submitting to the database. The code that I'm using works well on all Windows browsers and Firefox for Mac, but doesn't work on Safari - Mac. Could someone please help with suggestions or alternatives?
Here's the .js code.
Thanks
var swapCodes = new Array(8211, 8212, 8216, 8217, 8220, 8221, 8226, 8230); // dec codes from char at
var swapStrings = new Array("--", "--", "'", "'", '"', '"', "*", "...");
function cleanWordClipboard(input) {
// debug for new codes
// for (i = 0; i < input.length; i++)
//alert("'" + input.charAt(i) + "': " + input.charCodeAt(i));
var output = input;
for (i = 0; i < swapCodes.length; i++) {
var swapper = new RegExp("\\u" + swapCodes[i].toString(16), "g"); // hex codes
output = output.replace(swapper, swapStrings[i]);
}
return output;
}
function cleanWord(){
var t = document.getElementsByTagN ame("texta rea");
var i;
for(i=0;i<t.length;i++){
t[i].value = cleanWordClipboard(t[i].va lue);
}
}
Here's the .js code.
Thanks
var swapCodes = new Array(8211, 8212, 8216, 8217, 8220, 8221, 8226, 8230); // dec codes from char at
var swapStrings = new Array("--", "--", "'", "'", '"', '"', "*", "...");
function cleanWordClipboard(input) {
// debug for new codes
// for (i = 0; i < input.length; i++)
//alert("'" + input.charAt(i) + "': " + input.charCodeAt(i));
var output = input;
for (i = 0; i < swapCodes.length; i++) {
var swapper = new RegExp("\\u" + swapCodes[i].toString(16),
output = output.replace(swapper, swapStrings[i]);
}
return output;
}
function cleanWord(){
var t = document.getElementsByTagN
var i;
for(i=0;i<t.length;i++){
t[i].value = cleanWordClipboard(t[i].va
}
}
ASKER
third
Thanks for the comment. Unfortunately it didn't work. With the coding you suggested, the script no longer works on FF-Win.
Thanks for the comment. Unfortunately it didn't work. With the coding you suggested, the script no longer works on FF-Win.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I've updated the code to your suggestion. My Mac tester will run it through the paces when he gets off work tonight. I will keep you posted. Thanks.
Any folks with Macs out there want to help out testing, please let me know!
Any folks with Macs out there want to help out testing, please let me know!
ASKER
I've done the testing and it seems to be working.
Thanks very much!
Thanks very much!
welcome. ;-)
t[i].value = cleanWordClipboard(t[i].va
with
t[i].innerHTML = cleanWordClipboard(t[i].in