Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> ilosc znaków, w textarea
bronx
post
Post #1





Grupa: Zarejestrowani
Postów: 333
Pomógł: 0
Dołączył: 4.03.2004

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


witam

jak ma wyglądać skrypt który pokazuje ile jeszcze znaków można wpisać w odpowiedni formularz (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif)

z góry dzieki za pomoc

pozdrawiam
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
miedzna
post
Post #2





Grupa: Zarejestrowani
Postów: 401
Pomógł: 1
Dołączył: 10.03.2004
Skąd: Warszawa

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


Cytat(bronx @ 2004-07-03 17:21:14)
witam

jak ma wyglądać skrypt który pokazuje ile jeszcze znaków można wpisać w odpowiedni formularz (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif)

z góry dzieki za pomoc

pozdrawiam

Tu scrypt:

  1. <script type="text/javascript">
  2. var ns6=document.getElementById&&!document.all
  3. function restrictinput(maxlength,e,placeholder){
  4. if (window.event&&event.srcElement.value.length>=maxlength)
  5. return false
  6. else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
  7. var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
  8. if (pressedkey.test(String.fromCharCode(e.which)))
  9. e.stopPropagation()
  10. }
  11. }
  12. function countlimit(maxlength,e,placeholder){
  13. var theform=eval(placeholder)
  14. var lengthleft=maxlength-theform.value.length
  15. var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
  16. if (window.event||e.target&&e.target==eval(placeholder)){
  17. if (lengthleft<0)
  18. theform.value=theform.value.substring(0,maxlength)
  19. placeholderobj.innerHTML=lengthleft
  20. }
  21. }
  22. function displaylimit(thename, theid, thelimit){
  23. var theform=theid!=""? document.getElementById(theid) : thename
  24. var limit_text='<font color="red" size="2"><b><span id="'+theform.toString()+'">'+thelimit+'</span></b></font> znaków do wprowadzenia.'
  25. if (document.all||ns6)
  26. document.write(limit_text)
  27. if (document.all){
  28. eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
  29. eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
  30. }
  31. else if (ns6){
  32. document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true);
  33. document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true);
  34. }
  35. }



W form dajesz name="sampleform"
<form action="dodaj.php" method="post" name="sampleform">

a przy inpucie:
<input type="text" name="tytul">
<script>
displaylimit("document.sampleform.tytul","",60)
</script>

calosc wyglądała by tak:

  1. <script type="text/javascript">
  2. var ns6=document.getElementById&&!document.all
  3. function restrictinput(maxlength,e,placeholder){
  4. if (window.event&&event.srcElement.value.length>=maxlength)
  5. return false
  6. else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
  7. var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
  8. if (pressedkey.test(String.fromCharCode(e.which)))
  9. e.stopPropagation()
  10. }
  11. }
  12. function countlimit(maxlength,e,placeholder){
  13. var theform=eval(placeholder)
  14. var lengthleft=maxlength-theform.value.length
  15. var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
  16. if (window.event||e.target&&e.target==eval(placeholder)){
  17. if (lengthleft<0)
  18. theform.value=theform.value.substring(0,maxlength)
  19. placeholderobj.innerHTML=lengthleft
  20. }
  21. }
  22. function displaylimit(thename, theid, thelimit){
  23. var theform=theid!=""? document.getElementById(theid) : thename
  24. var limit_text='<font color="red" size="2"><b><span id="'+theform.toString()+'">'+thelimit+'</span></b></font> znaków do wprowadzenia.'
  25. if (document.all||ns6)
  26. document.write(limit_text)
  27. if (document.all){
  28. eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
  29. eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
  30. }
  31. else if (ns6){
  32. document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true);
  33. document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true);
  34. }
  35. }
  36.  
  37.  
  38.  
  39. <form action="dodaj.php" method="post" name="sampleform">
  40. <B>Tytuł</B> (max 60 znaków)<BR>
  41. <input type="text" name="tytul" maxlength="60">
  42. displaylimit("document.sampleform.tytul","",60)
  43. <BR><BR>
  44. <B>Wstęp</B> (max 200 znaków)<BR>
  45. <textarea cols="60" rows="5" name="wstep"></textarea>
  46. displaylimit("","wstep",200)
  47. <input type="submit" name="submit" value="Wy&para;lij" class="ramka" style="margin-top:5px;">
  48. </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: 17.10.2025 - 19:58