Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [JS] document has no properties
Archbishop
post
Post #1





Grupa: Zarejestrowani
Postów: 29
Pomógł: 0
Dołączył: 26.10.2006
Skąd: Kraków

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


Czyli staly problem, ale tym razem na nowo smile.gif

Moj problem dotyczy tylko i wylacznie przegladarki firefox w wersji 2.x.x.x.
Pod 3.0, jak i pod IE/Opera/Chrome moj skrypt dziala bez zarzutu.

Wyglada to tak.
W pliku htmlowym mam link:
  1. <a href="#" title="Przenieś zaznaczone wiadomości do wskazanego folderu" onclick="moveMessages(); return false;" target="_self">


Ww. funkcja wyglada tak:
  1. function moveMessages()
  2. {
  3.      var toFolder;
  4.  
  5.      toFolder = crossModalDialog ('toolbar.php?showFolders=1&move=1', 300, 400);
  6.      if (toFolder)
  7.      {
  8.            copyOrMoveMessages(true, toFolder);
  9.      }
  10. }


funkcja crossModalDialog:

  1. function crossModalDialog(url, width, height)
  2. {
  3.      var top;
  4.      var left;
  5.  
  6.      top = (screen.availHeight - height) / 2;
  7.      left = (screen.availWidth - width) / 2;
  8.  
  9.      if (top < 0) top = 0;
  10.      if (left < 0) left = 0;
  11.  
  12.      if (window.showModalDialog)
  13.      {
  14.            return window.showModalDialog(url, window.self, 'dialogHeight: '+height+'px; dialogWidth: '+width+'px; help: no; resizable: yes; scroll: yes; status: no;');
  15.      }
  16.      else
  17.      {
  18.            if (dialogWindow && !dialogWindow.closed && dialogWindow.close)
  19.            {
  20.                  dialogWindow.close();
  21.            }
  22.            dialogWindow = window.open(url, '_blank', 'toolbar=no,menubar=no,directories=no,resizable=yes,width='+width+',height='+height+',top='+top+',left='+left+',scrollbars=yes,status=no');
  23.            return null;
  24.      }
  25. }

W tym momencie mamy okienko z lista folderow.
Sa tam linki do skryptu ze zdarzeniami onClick, np. "onclick="copyOrMoveMessages(true, 'INBOX.Drafts');"
Wybieram ten link i mamy:

copyOrMoveMessages:
  1. function copyOrMoveMessages(isMove, toFolder)
  2. {
  3.      if (window.dialogArguments)
  4.      {
  5.            window.returnValue = toFolder;
  6.            return;
  7.      }
  8.  
  9.      if (isMove)
  10.      {
  11.            moveMessagesTo(toFolder);
  12.      }
  13.      
  14. }


moveMessagesTo:
  1. function moveMessagesTo(toFolder)
  2. {
  3.      return selectedMessagesAction('move', false, toFolder);
  4. }


selectedMessagesAction:

  1. function selectedMessagesAction(action, confirmText, toFolder)
  2. {
  3.      if (!countSelectedMessages())
  4.      {
  5.            alert(getParameter('selectMessages'));
  6.            return false;
  7.      }
  8.  
  9.      if (!confirmText || confirm(confirmText))
  10.      {
  11.            document.forms['messages'].elements['action'].value = action;
  12.            if (toFolder)
  13.            {
  14.                  document.forms.messages.elements['to'].value = toFolder;
  15.            }
  16.            document.forms.messages.submit();
  17.      }
  18.      return true;
  19. }


I teraz ta newralgiczna funckja:
  1. function countSelectedMessages()
  2. {
  3.      var count = 0;
  4.      var i;
  5.  
  6.    var f = document.getElementById('messages');
  7.  
  8.            for (i=0; i<f.elements.length; i++)
  9.            {
  10.                  if (f.elements[i].name.indexOf('mid[') == 0 && f.elements[i].checked)
  11.                  {
  12.                        count++;
  13.                  }
  14.            }
  15.  
  16.      return count;
  17. }

No i efekt jest taki, za zaznaczam wiadomosci, klikam na link, wyskakuje okienko z lista folderow i gdy klikam na folder, to JavaScript zwraca blad "f has no properties" i wskazuje na linijke "for (i=0; i<f.elements.length; i++)" w funkcji countSelectedMessages.

Probowalem juz zamienic document.getElementById('messages') na document.getElementsById('messages')[0].
Probowalem tez z with(document.forms.messages){..}.
Niestety ciagle jest ten sam problem - firefox 2...

Ma ktos jakas koncepcje? smile.gif

Ten post edytował Archbishop 14.10.2008, 12:49:02


--------------------
Destruction cometh; and they shall seek peace, and there shall be none. - Bible, Ezekiel 7:25
Go to the top of the page
+Quote Post
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




document.getElementById('messages');
czyli nie masz pola o ID=messages smile.gif


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

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





Grupa: Zarejestrowani
Postów: 29
Pomógł: 0
Dołączył: 26.10.2006
Skąd: Kraków

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


Cytat(nospor @ 14.10.2008, 10:24:24 ) *
document.getElementById('messages');
czyli nie masz pola o ID=messages smile.gif


Niestety jest.. :/

  1. <form method="post" id="messages" name="messages" action="messages.php">


Ponadto funkcja operujaca na tej formatce (wywolana jeszcze z poziomu okna bazowego) bez problemu przechwytuje te forme.
A jest ona bardzo podobna do tej, przy ktorej mi wyrzuca blad:

  1. function selectMessages(status)
  2. {
  3.      var i;
  4.  
  5.    var f = document.getElementsByName('messages')[0];
  6.    alert(f);
  7.            for (i=0; i<f.elements.length; i++)
  8.            {
  9.                  if (f.elements[i].name.indexOf('mid[') == 0)
  10.                  {
  11.                        f.elements[i].checked = status;
  12.                  }
  13.            }
  14.  
  15. }


W f siedzi to co powinno: "object HTMLFormElement"...

EDIT: Przy funckji crossModalDialog wkradl sie maly grzybek: tam, gdzie jest "window.self" ma byc "true".

Nikt nie ma koncepcji co moze byc przyczyna bledow?
Nie dziala to tylko w ff 2.x.
Za kazda sugestie z gory dziekuje smile.gif

Ten post edytował Archbishop 14.10.2008, 10:05:20


--------------------
Destruction cometh; and they shall seek peace, and there shall be none. - Bible, Ezekiel 7:25
Go to the top of the page
+Quote Post
thm
post
Post #4





Grupa: Zarejestrowani
Postów: 52
Pomógł: 10
Dołączył: 6.10.2008
Skąd: Lublin

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


Kod
<form name="myForm">
<input type="text" value="foo" />
<input type="text" value="boo" />
</form>

<script type="text/javascript">
var x=document.getElementsByName("myForm");

for (var i=0;i<x[0].length;i++) {
  alert(x[0].elements[i].value);
}
</script>
Go to the top of the page
+Quote Post
Archbishop
post
Post #5





Grupa: Zarejestrowani
Postów: 29
Pomógł: 0
Dołączył: 26.10.2006
Skąd: Kraków

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


Niestety tym razem wyskakuje komunikat:

Cytat
Błąd: f[0] has no properties



Czyli dalej jakby nie widział formy :/
Czy może mieć wpływ na to fakt, że funkcja jest wywoływana z poziomu okienka potomnego?

EDIT: Zrobiłem!!
Pomogło: var f = window.opener.document.getElementsByName("messages");

Ten post edytował Archbishop 24.10.2008, 09:54:38


--------------------
Destruction cometh; and they shall seek peace, and there shall be none. - Bible, Ezekiel 7:25
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: 21.08.2025 - 01:59