I have an textarea in my form and I want to show how many characters are entered. I have put the code in a test script below.
I had a problem because the js count was not matching strlen().
I think that I have found the problem:
On my keyboard I also have Turkish characters so when I enter a ğ
( on my screen this shows as a g with a "hat" on top)
the js counter shows just one character - but when I submit the form the
strlen() returns 6.
So whenever I enter a few turkish characters - the count jumps.
My problem is that my web page has the javascript counter on it but the checking is done server-side with php uing strlen().
They will work fine so long as ONLY normal characters are used. Is there any way to make them both show the same count when forign characters are entered ?
If you load this little script you will see the problem. Try a couple of forign characters and see what I mean.
<?php
$N_test = strip_tags(trim($_POST["test"]));
echo "<br>"."$N_test" ;
echo "<br>".strlen($N_test);
$test1 = "asbdget ght wety urlk mnga thetabdn tersl rjhts eh";
echo "<br>"."$test1" ;
echo "<br>".strlen($test1);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<script type="text/javascript">
<!--
function chk_length(){
document.main_fm.opt_lg_count.value='Count = '+(document.main_fm.test.value.length)
} // end of function
document.onkeyup=chk_length
// -->
</script>
</head>
<body>
<div style='width:300px;position:absolute;left:300px; top:300px;' >
<form name="main_fm" action="zz.php" method = 'POST'>
<textarea rows = 18 cols = 50 name='test' " />
</textarea><br>
<input class = 'form_box' type='TEXT' name='opt_lg_count' size = '25' />
<br>
<center><input type = 'submit' value='Submit'><br>
Submit.</center>
</form>
</div>
</body>
</html>
Thanks