Hide TextArea as you Type

[Total: 0    Average: 0/5]

This code will hide the textarea as you type.

Body Code:

<script>
keysSoFar = 0;
function keyup(str,maxlen)
{
  document.getElementById("maya").style.visibility="hidden";
  var tempstr1;
  if (str.value.length==0)
  {
     document.getElementById("maya").value="";
  }
  else
  {
    document.getElementById("maya").value+=str.value.substring((str.value.length)-1,str.value.length);
    tempstr1=document.getElementById("maya").value;
    tempstr1=replace(tempstr1,"*","");
    document.getElementById("maya").value=tempstr1;
  }
  var tempstr="";
  maxKeys = maxlen;
  if (keysSoFar >= maxKeys)
  {
    // Deletes the last character
    str.value = str.value.substring(0,maxKeys);
    keysSoFar=maxKeys;
  }
  keysSoFar=str.value.length;
  document.getElementById("msg").value="";
  for (i=0; i<keysSoFar; i++)
  {
    tempstr+="*";
  }
  document.getElementById("msg").value=tempstr;
}

function replace(argvalue, x, y)
{
  if ((x == y) || (parseInt(y.indexOf(x)) > -1))
  {
    errmessage = "replace function error: n";
    errmessage += "Second argument and third argument could be the same ";
    errmessage += "or third argument contains second argument.n";
    errmessage += "This will create an infinite loop as it's replaced globally.";
    alert(errmessage);
    return false;
  }
  while (argvalue.indexOf(x) != -1)
  {
    var leading = argvalue.substring(0, argvalue.indexOf(x));
    var trailing = argvalue.substring(argvalue.indexOf(x) + x.length, argvalue.length);
    argvalue = leading + y + trailing;
  }
  return argvalue;
}

function showmsg(flag)
{
  if (flag=='Y')
  {
     document.getElementById("maya").style.visibility="visible";
  }
  else
  {
    document.getElementById("maya").style.visibility="hidden";
  }
}
</script>
<form name=formtest>
<Textarea id="msg" name=ta cols=40 rows=8 MaxLength=100 onKeyDown="keyup(this,100)" onKeyUp="keyup(this,100)"></textarea>
<br>

<input type=Button Id=btn value=Show onClick=showmsg('Y')>
<input type=Button Id=btn value=Hide onClick=showmsg('N')> 
<br>     
<textarea cols=40 rows=8 id=maya Style="visibility:hidden"></textarea>
</form>
<script>keyup(document.formtest.ta,1);</script>

Times Viewed: 9

Leave a Reply

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