Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [FCK] MaxLength
umatik
post
Post #1





Grupa: Zarejestrowani
Postów: 209
Pomógł: 0
Dołączył: 17.05.2002
Skąd: lodz

Ostrzeżenie: (0%)
-----


jak mam dowiedzieć sie jak długi jest txt w edytorze ? chcialem zablokować długość wpisywanego txt powedzmy do 500 znaków....
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Kshyhoo
post
Post #2





Grupa: Opiekunowie
Postów: 3 855
Pomógł: 317
Dołączył: 4.01.2005
Skąd: że




Jeżeli chcesz zrobić walidację w ten sposób, pobaw się tym kodem:
  1. <script Language = "JavaScript">
  2. function textCounter(theField,theCharCounter,theLineCounter,maxChars,maxLines,maxPerLine)
  3. {
  4. var strTemp = "";
  5. var strLineCounter = 0;
  6. var strCharCounter = 0;
  7.  
  8. for (var i = 0; i < theField.value.length; i++)
  9. {
  10. var strChar = theField.value.substring(i, i + 1);
  11.  
  12. if (strChar == '\n')
  13. {
  14. strTemp += strChar;
  15. strCharCounter = 1;
  16. strLineCounter += 1;
  17. }
  18. else if (strCharCounter == maxPerLine)
  19. {
  20. strTemp += '\n' + strChar;
  21. strCharCounter = 1;
  22. strLineCounter += 1;
  23. }
  24. else
  25. {
  26. strTemp += strChar;
  27. strCharCounter ++;
  28. }
  29. }
  30.  
  31. theCharCounter.value = maxChars - strTemp.length;
  32. theLineCounter.value = maxLines - strLineCounter;
  33. }
  34. <form name="theForm" method="post" action="">
  35. <textarea name="myText" cols="25" rows="10" wrap="VIRTUAL" nKeyUp="textCounter(theForm.myText,theForm.remChars,remLines,6000,165,100);"></textarea>
  36. <br><input name=remChars type=text value="6000" size=3 maxlength=3 readonly> znaków zostało
  37. <br><input name=remLines type=text value="165" size=3 maxlength=3 readonly>linii zostało
  38. </form>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 13.10.2025 - 19:02