Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [FCK] MaxLength
Forum PHP.pl > Forum > Po stronie przeglądarki
umatik
jak mam dowiedzieć sie jak długi jest txt w edytorze ? chcialem zablokować długość wpisywanego txt powedzmy do 500 znaków....
Kshyhoo
Stawiałbym na:
  1. <form name="myform" action=... method=...>
  2. <textarea name="text_1" id="text_1"></textarea>
  3. <input type="text" name="text_1_cnt" id="text_1_cnt" value="255">
  4. <script type="text/javascript">
  5. var oFCKeditor_1 = new FCKeditor('testo_1');
  6. oFCKeditor_1.BasePath = '../FCKeditor/';
  7. oFCKeditor_1.Config['MaxLength'] = 255;
  8. oFCKeditor_1.Config['CounterName'] = 'text_1_cnt';
  9. oFCKeditor_1.ReplaceTextarea();
  10. </form>

I do tego zainteresuj się wtyczkami:
umatik
próbowałem tego ale nie wiem dlaczego nie działa mi .... szczerze mówiąc próbowełem z wyczkami ale nigdzie nie znalazlem jasnego opisu jak się je stosuje.

ale zrobiłem cos takiego :

Kod
function removeHTMLTags(txt){
  var strInputCode = txt
  var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
  return strTagStrippedText
}
function sprawdz(){
  var str = FCKeditorAPI.GetInstance('tresc_pl').GetHTML(true);
  t = removeHTMLTags(txt)
  alert(t.length)
}


no i jak podam:

  1. <li>1</li>
  2. <li>2</li>
  3. <li>3</li>


to alert zamiast 3 pokazuje mi 19 dlaczego ?

Kshyhoo
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>
umatik
hmm gdyby to bylo "czyste" textarea nie było by problemów, ja muszę policzyć, lub ograniczyć ilość znaków w edytorze FCK, a to dla mnie juz jest problem, bo aż tak dobrze nie znam sie na JS.
Kshyhoo
Zmień edytor.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.