thanks for your suggestion, planetsim.
i had tried that but it was only replacing a single instance of the characters. thus, if the user were to enter <><img src='http://foo.com/advertisement.jpg'> then that image would display in the form. as i said, i'll be using htmlspecialchars() on the php end of things, but i don't want to encourage any chumps to try that.
I think i've managed to get it working with this code:
function cleaner(findString, replaceString, thaString) {
var resultAry = thaString.split(findString);
var result = resultAry[0];
for (i=1; i<resultAry.length; i++) {
result += replaceString + resultAry[i];
}
return result;
}
function cleanString(arg) {
var newString = new String(arg);
newString = cleaner('&', '&', newString);
newString = cleaner('<', '<', newString);
newString = cleaner('>', '>', newString);
return newString;
} // cleanString
EDIT: your code is right on the money! my bad. i'm still getting used to the no quotes concept and forget the 'g' flag.
this also appears to work:
function cleanString(arg) {
var newString = new String(arg);
newString = newString.replace(/&/g, '&');
newString = newString.replace(/</g, '<');
newString = newString.replace(/>/g, '>');
return newString;
} // cleanString