Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Wywołanie funkcji po zamknięciu popup
maciequs
post
Post #1





Grupa: Zarejestrowani
Postów: 13
Pomógł: 0
Dołączył: 27.01.2008
Skąd: Warszawa

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


mam taki kod ktory wpisuje tagi bbcode do textarea:

Kod
function addText(elname, wrap1, wrap2) {
    if (document.selection) { // for IE
        var str = document.selection.createRange().text;
        document.forms['inputform'].elements[elname].focus();
        var sel = document.selection.createRange();
        sel.text = wrap1 + str + wrap2;
        return;
    } else if ((typeof document.forms['inputform'].elements[elname].selectionStart) != 'undefined') { // for Mozilla
        var txtarea = document.forms['inputform'].elements[elname];
        var selLength = txtarea.textLength;
        var selStart = txtarea.selectionStart;
        var selEnd = txtarea.selectionEnd;
        var oldScrollTop = txtarea.scrollTop;
        //if (selEnd == 1 || selEnd == 2)
        //selEnd = selLength;
        var s1 = (txtarea.value).substring(0,selStart);
        var s2 = (txtarea.value).substring(selStart, selEnd)
        var s3 = (txtarea.value).substring(selEnd, selLength);
        txtarea.value = s1 + wrap1 + s2 + wrap2 + s3;
        txtarea.selectionStart = s1.length;
        txtarea.selectionEnd = s1.length + s2.length + wrap1.length + wrap2.length;
        txtarea.scrollTop = oldScrollTop;
        txtarea.focus();
        return;
    } else {
        insertText(elname, wrap1 + wrap2);
    }
}

function insertText(elname, what) {
    if (document.forms['inputform'].elements[elname].createTextRange) {
        document.forms['inputform'].elements[elname].focus();
        document.selection.createRange().duplicate().text = what;
    } else if ((typeof document.forms['inputform'].elements[elname].selectionStart) != 'undefined') { // for Mozilla
        var tarea = document.forms['inputform'].elements[elname];
        var selEnd = tarea.selectionEnd;
        var txtLen = tarea.value.length;
        var txtbefore = tarea.value.substring(0,selEnd);
        var txtafter =  tarea.value.substring(selEnd, txtLen);
        var oldScrollTop = tarea.scrollTop;
        tarea.value = txtbefore + what + txtafter;
        tarea.selectionStart = txtbefore.length + what.length;
        tarea.selectionEnd = txtbefore.length + what.length;
        tarea.scrollTop = oldScrollTop;
        tarea.focus();
    } else {
        document.forms['inputform'].elements[elname].value += what;
        document.forms['inputform'].elements[elname].focus();
    }
}


i wywołuje funkce openwindow, okienko ma kilka linków z wartosciami.
chciałbym href="java script:funkcja()" wywołać funkcje zamykającą okienko i jednoczesnie przekazującą wartości do funkcji addText, która dopisuje do tresci textarea juz wpisanego tekstu

mam narazie taką funkcję:

Kod
function ret(Val) {
      
       opener.document.getElementById("PoleInput").value=unescape(Val);
       window.close();
   }


i to działa ale "nadpisuje" wartosc w polu textarea.
Go to the top of the page
+Quote Post
lord_t
post
Post #2





Grupa: Zarejestrowani
Postów: 603
Pomógł: 131
Dołączył: 24.07.2007
Skąd: Górny Śląsk

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


Zamień :
Kod
function ret(Val) {
      
       opener.document.getElementById("PoleInput").value=unescape(Val);
       window.close();
   }


na:
Kod
function ret(Val) {
      
       opener.document.getElementById("PoleInput").value+=unescape(Val);
       window.close();
   }


--------------------
Go to the top of the page
+Quote Post
maciequs
post
Post #3





Grupa: Zarejestrowani
Postów: 13
Pomógł: 0
Dołączył: 27.01.2008
Skąd: Warszawa

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


dzięki

a jak wywołać tą funkcję addText z popup'a?
Go to the top of the page
+Quote Post
lord_t
post
Post #4





Grupa: Zarejestrowani
Postów: 603
Pomógł: 131
Dołączył: 24.07.2007
Skąd: Górny Śląsk

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


Tu mnie zbiłeś z tropu;p No jeśli ta funkcja jest w popupie to po prostu jej używasz:
np. tak (uwaga: przykład taki z głowy = nie koniecznie ma sens;), ale powinien zadziałać)

Kod
function ret(Val) {
      
       opener.document.getElementById("PoleInput").value+=unescape(Val);
       addText('name_jakiegos_elementu', '[b]', '[/b]')
       window.close();
   }


--------------------
Go to the top of the page
+Quote Post
jacekl
post
Post #5





Grupa: Zarejestrowani
Postów: 36
Pomógł: 7
Dołączył: 4.05.2008
Skąd: Warszawa

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


Możesz wywołać tę funkcję podając nazwę okna, w którym została zdefiniowana:

  1. <?php
  2. opener.addText(...)
  3. ?>


JL
Go to the top of the page
+Quote Post
maciequs
post
Post #6





Grupa: Zarejestrowani
Postów: 13
Pomógł: 0
Dołączył: 27.01.2008
Skąd: Warszawa

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


pomogło dzięki
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 19.08.2025 - 21:37