Escape Code Generator

Ever needed to paste some html code but find it gets interpreted as html rather than text? By escaping the characters < and > you can "plain text-ize" your html code to display as raw html tags rather than formatted html.

Try It Here:


Source Code:

This part needs to go in the <head> section of your document
<SCRIPT LANGUAGE="Javascript">
<!--

/*********************************************************
 * convert < and > to their escape codes
 *********************************************************/
function toEscapes(str) 
{
  var nextgtlt;
  
  nextgtlt = -1;
  while (str.indexOf("<", nextgtlt + 1) > -1) 
  {
    nextgtlt = str.indexOf("<", nextgtlt + 1);
    var newStr = str.substr(0, nextgtlt);
    newStr += "<";
    newStr = newStr + str.substr(nextgtlt + 1, str.length);
    str = newStr;
  }

  nextgtlt = -1;
  while (str.indexOf(">", nextgtlt + 1) > -1) 
  {
    nextgtlt = str.indexOf(">", nextgtlt + 1);
    var newStr = str.substr(0, nextgtlt);
    newStr += ">";
    newStr = newStr + str.substr(nextgtlt + 1, str.length);
    str = newStr;
  }
  
  return str;
  
} 
-->
</script>
This form portion goes in the body of your document:
<FORM ACTION="" ID="Translator">
<TextArea name="source" id="source" cols=50 
rows=10></textarea>
<br>
<input type="button" id="run" value="toEscapes" name="run" 
onClick="document.forms.Translator.source.value 
= toEscapes(document.forms.Translator.source.value);">
</FORM>

Jessica's Webpage -> Computers -> Escape Codes