Andreas Mueck: Nur eine bestimmte Anzahl an Zeichen in einem mehrzeiligen Textfeld

Beitrag lesen

Hallo Frank,

probier mal folgendes aus :

<html>
<head>
<title>titel</title>

<script language="JavaScript">

<!--
function CheckStr(userInput) {

StrLen = window.document.eingabe.textfeld.value.length;  

if (StrLen > 55 ) {window.document.eingabe.textfeld.value = window.document.eingabe.textfeld.value.substring(0,55); StrLeft = 0;}
                else {StrLeft = 55 - StrLen;}

document.eingabe.Len.value = StrLeft;}

//-->
</script>
</head>
<body>

<table>
<tr><th>
<form name="eingabe">

<INPUT NAME=Len VALUE=55 SIZE=3> Zeichen sind noch drin ;-) </table>

<textarea cols=26 rows=7 name="textfeld" MAXLENGTH="55" onChange="CheckStr(this)" onFocus="CheckStr(this)" onBlur="CheckStr(this)" onKeyDown="CheckStr(this)" onKeyUp="CheckStr(this)" STYLE="overflow:hidden"></textarea>
</FORM>

</body>
</html>

Um die Anzahl der Zeichen zu verändern, mache einfach ein Suchen/Ersetzen auf den Wert 55.

Hoffe es funzt.

Bis dann
Andreas