Last modified on 22 March 2006, at 15:21

Coding Cookbook/JavaScript Encode

Encode special characters in a string, so that it can be displayed using JavaScript

VBScript solutionEdit

function JSEncode (sInput)
  JSEncode = sInput
  JSEncode = Replace (JSEncode, chr(0), "")
  JSEncode = Replace (JSEncode, "'", "\'")
  JSEncode = Replace (JSEncode, """", "\""")
  JSEncode = Replace (JSEncode, "&", "\x26")
  end function