Click to See Complete Forum and Search --> : type in textarea only this


vinsa
02-25-2003, 12:09 PM
Hello! First sorry for my english.
I need from javascript.
DATA:
I have 2 textarea (X & Y).
"X" have value="My name is John Smith" (example).
"Y" have not value.
I want, when I type in textarea "Y", the script must
compare symbols in "X" with symbols
in "Y" and when the symbols not fall -> to can't type
another symbols. So, I will can type in "Y" only
"My name is John Smith". Is this possible?
Thank you previous!
My e-mail: iivanov2@abv.bg
All the best!

AdamBrill
02-25-2003, 01:01 PM
Try this code:
<html>
<head>
<script language=javascript>
function check()
{
if(form1.T1.value.length>=form1.T2.value.length)
{
part=form1.T1.value.substring(0,form1.T2.value.length);
x=0;
do
{
if(form1.T1.value.substring(x,x+1)!=form1.T2.value.substring(x,x+1))
{
form1.T2.value=form1.T2.value.substring(0,x);
break;
}
x++;
} while(x<form1.T2.value.length)
}
else
{
form1.T2.value=form1.T2.value.substring(0,form1.T1.value.length);
}
setTimeout("check()",50);
}
</script>
</head>
<body onload="check()">
<form name=form1>
<input type="text" name="T1" size="20">
<input type="text" name="T2" size="20">
</form>
</body>
</html>