JavaScript employing the .substring call

First example: A "Smut Engine" to Replace Unwanted Words in Form Submissions

Depending upon the audience for your Web Site, you may wish to screen form submissions (at least perfunctorily) for content before processing them. This routine uses the .substring call to simply replace "offending" words by "taking the string apart" and then "reassembling" it.

Type some dirty words here and click the submit button.



Second example: Stripping the HTML from Visitor Entries

If entries will be displayed later, it may be important to "disable" any direct HTML entries folks decide they want to enter. Here we just look for left and right carets (<>) and use the .substring call to replace them with "&lt;" and "&gt;" respectively.

Type some HTML into the text element below. Then click the submit button to see how it is altered.


 
  
 
Copy-N-Paste Window

Simply copy (type Control-c or Apple-c) the script from the window below. Then paste it (type Control-v or Apple-v) into your text editor and save (Control-s or Apple-s).