Replacement of Text Improved

[Total: 0    Average: 0/5]

This will replace the words even if punctuation delineates the words.

Body Code:

<a href='javascript:makeSpellFix("Debounce","Denounce");'>Denounce</a>
<a href='javascript:makeSpellFix("Debounce","De bounce");'>De bounce</a>
<a href='javascript:makeSpellFix("Debounce","De-bounce");'>De-bounce</a>
<a href='javascript:makeSpellFix("Debounce","Deb ounce");'>Deb ounce</a>
<a href='javascript:makeSpellFix("Debounce","Deb-ounce");'>Deb-ounce</a>
<a href='javascript:makeSpellFix("Debounce","");'></a>

<script>
function makeSpellFix(_out,_add)
{
  var temp = "" + document.myform.subject.value;
  var x=0;
  var DELIN=new Array(' ', ',', '.', '!');
      DELIN[x++]=' ';
      DELIN[x++]='.';
      DELIN[x++]=',';
      DELIN[x++]='<';
      DELIN[x++]='>';
      DELIN[x++]='!';
      DELIN[x++]=String.fromCharCode(13); /* new line */

  for(var _ex=0;_ex<DELIN.length;_ex++)
  {
    var out=_out+DELIN[_ex];
    var add=_add+DELIN[_ex];
    var pos=0;
    var a=0;
    var i=0;
    while (temp.indexOf(out)>-1)
    {
      pos= temp.indexOf(out);
      temp = "" + (temp.substring(0, pos) + add + temp.substring((pos + out.length), temp.length));
    }
  }
  /* this finds the replacement if it is the last item on the input string */
  if(temp.indexOf(_out)==temp.length-_out.length)
    temp=""+temp.substring(0,temp.length-_out.length)+_add.substring(0,_add.length);
  
  document.myform.subject.value = temp;
}
</script>

<form name=myform>
<textarea name=subject cols=40 rows=10>
Debounce Debounce Debounce, Debounce. Debounce  Debounce! Debounce
</textarea>

<a href="javascript:alert(escape(document.myform.subject.value))">click</a>

Times Viewed: 1

Leave a Reply

Your email address will not be published. Required fields are marked *