You should be able to put this into a ".inc" file and then just do
at the top of each page.
If a page doesn't happen to have a txtName
field, I don't think it will hurt. The sub just won't do anything, then.
I hope you are aware that this means that your pages will *ONLY* run with MSIE browsers, as only MSIE allows VBScript in the browser.
Finally, you can simplify the heck out of that code thusly:
' do this outside the SUB for efficiency:
reZap = New RegExp
reZap.Pattern = "[\'\/\!\?]"
reZap.Global = True
Dim fld = document.body.all("txtName")
fld.value = reZap.Replace( fld.value, "" )
This also makes it easy to add other zappable characters to the list, just by adding them into the .Pattern value.
Alternatively, you could specify only the characters you want to *KEEP* by doing something like:
reZap.Pattern = "[^a-zA-Z0-9\,\s\-]"
which will say "zap all characters *EXCEPT* those I list". (The leading ^ character inverts the sense of the match.)
function txtname_onblur( )
var fld = document.forms.txtName;
fld.value = fld.value.replace( /[\'\/\!\?]/g, "" );