Article ID: 192033
Article Last Modified on 8/11/2005
=Server.HTMLEncode([fieldname])
example: =MyHTMLEncode([field1])
// This function is time-consuming, and it is best to avoid
// using it unless it is absolutely necessary.
function myHTMLEncode(stData)
{
// A temporary variable to hold the existing/modified character.
chTemp = "";
// A new string, which will be generated from chTemp.
stTemp = "";
// The length of the string being passed in.
nLength = toString(stData).length;
// Go through the string character by character.
for(i = 0; i < nLength; i++)
{
// Get the current character and put it in the temp character.
chTemp = stData.charAt(i);
// You may need to add more special case characters.
switch(chTemp)
{
case "<" : chTemp = "<"; // Replace (<) with (<)
break;
case ">" : chTemp = ">"; // Replace (>) with (>)
break;
case "&" : chTemp = "&"; // Replace (&) with (&)
break;
case '""' : chTemp = """; // Replace (") with (")
break;
default : break; // Do nothing, the current character is
// okay.
}
// Add the temp character to the end of the temp string.
stTemp = stTemp + chTemp;
}
// Return the properly formatted string.
return stTemp;
}
Keywords: kbbug kbctrl kbpending KB192033