Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q279 How can I ROT13 text in a textarea?

You are here: irt.org | FAQ | JavaScript | Text | Q279 [ previous next ]

<SCRIPT LANGUAGE="JavaScript"><!--
var coding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMabcdefghijklmnopqrstuvwxyzabcdefghijklm';

function rot13() {
   var value = document.myForm.myText.value;
   for (var text = '',i=0;i<value.length;i++) {
       character = value.charAt(i);
       position = coding.indexOf(character);
       if (position > -1)
           character = coding.charAt(position + 13);
       text += character;
   }
   document.myForm.myText.value = text;
}
//--></SCRIPT>

<FORM NAME="myForm">
<TEXTAREA COLS="80" ROWS="40" NAME="myText"></TEXTAREA>
<INPUT TYPE="BUTTON" onClick="rot13()" VALUE="Press Me">
</FORM>

©2018 Martin Webb