Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> wypełnanie textarea
dyktek
post
Post #1





Grupa: Zarejestrowani
Postów: 240
Pomógł: 0
Dołączył: 18.01.2004
Skąd: rzeszów / kraków

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


Witam, zastanawiam się jak ugryźć problem wypełniania pola textarea w taki sposób jak jest to zrealizowane tutaj na forum. Są znaczniki B I U w momencie gdy klikne na butonnik wklejany jest odpowiedni kod w miejsce kursora.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
revyag
post
Post #2





Grupa: Przyjaciele php.pl
Postów: 2 258
Pomógł: 16
Dołączył: 21.09.2004
Skąd: Kielce

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


Było o tym na forum, wystarczy poszukać. Do googli też warto zajrzeć:
cursor + textarea
Go to the top of the page
+Quote Post
dyktek
post
Post #3





Grupa: Zarejestrowani
Postów: 240
Pomógł: 0
Dołączył: 18.01.2004
Skąd: rzeszów / kraków

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


ok poradziłem sobie, dzięki za info (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)

  1. <script type="text/javascript">
  2. var cnt = new Array();
  3.  
  4. function kontr(bCode){      
  5.      var regKr = /(\*)/;      
  6.      var eLem = document.getElementById(bCode).value;      
  7.      regKr.test(eLem)?document.getElementById(bCode).value = '[ ' + bCode + ' ]' : document.getElementById(bCode).value = '[ ' + bCode + ' ]*';      
  8. }
  9.  
  10. function naw(N){
  11.      var regKr = /(\*)/;
  12.      var vN = document.getElementById(N).value;
  13.      return regKr.test(vN);
  14. }
  15.  
  16. function Paste(co){
  17.      kontr(co);
  18.      var ff = document.getElementById('tresc');
  19.            if (!cnt[co]) cnt[co] = 0;
  20.  
  21.            if(document.selection){
  22.                  document.formularz.tresc.focus();
  23.                  document.selection.createRange().text = naw(co)?'['+co+']':'[/'+co+']';
  24.            }
  25.            else if (ff.selectionStart || ff.selectionStart == 0) {
  26.                  ff.focus();
  27.                  var bC = naw(co)?'['+co+']':'[/'+co+']';
  28.                  ff.value = ff.value.substring(0,ff.selectionStart)+bC+ff.value.substring(ff.selectionEnd,ff.value.length);
  29.            }
  30.      cnt[co]++;
  31. }
  32.  
  33.  
  34. <input type="button" id="b" name="b" value="[ b ]" onClick="Paste('b');">
  35. <input type="button" id="i" name="i" value="[ i ]" onClick="Paste('i');">
  36. <input type="button" id="u" name="u" value="[ u ]" onClick="Paste('u');">
  37. <br /><br />
  38. <form id="formularz" name="formularz">
  39. <textarea id="tresc" name="tresc" style="width:400px; height:200px"></textarea>
  40. </form>


Ten post edytował dyktek 11.05.2006, 15:01:59
Go to the top of the page
+Quote Post

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: 24.08.2025 - 09:04