Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Javascript] 'null' jest pusty lub nie jest obiektem
fantek
post
Post #1





Grupa: Zarejestrowani
Postów: 51
Pomógł: 0
Dołączył: 9.10.2010

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


Witam. Na stronie http://machinesbook.com/beta/user/dashboard w panelu użytkownika mam dodawanie nowych Logbooków itd. Wszystko by było ok ale w IE po kliknięciu na add otwiera mi formularz rejestracyjny zamiast formularz do dodawania logbooków oraz w konsoli wywala mi błąd 'null' jest pusty lub nie jest obiektem (błąd odnosi się do linijki z "gebi('photos').appendChild(d);")


Funkcja w której wywala ten błąd:
  1. function addNewPhoto() {
  2. var max = 7;
  3. var num_img = $('input[name="photos[]"]').size() + $("a.delete").size();
  4. if((max!=0 && num_img<max) || max==0) {
  5. var id = 'p-' + photoIndex++;
  6.  
  7. var i = ce('input');
  8. i.setAttribute('type', 'file');
  9. i.setAttribute('name', 'photos[]');
  10.  
  11. var a = ce('a');
  12. a.style.fontSize = 'x-small';
  13. a.style.paddingLeft = '10px';
  14. a.setAttribute('href', '#');
  15. a.setAttribute('divid', id);
  16. a.onclick = function() { re(this.getAttribute('divid')); return false; }
  17. a.appendChild(document.createTextNode('Remove'));
  18.  
  19. var d = ce('div');
  20. d.setAttribute('id', id);
  21. d.setAttribute('style','padding: 4px 0;')
  22.  
  23. d.appendChild(i);
  24. d.appendChild(a);
  25.  
  26. gebi('photos').appendChild(d);
  27. if( num_img +1 == max){
  28. $('#addPhotoLink').addClass('hide_box');
  29. }
  30.  
  31. } else {
  32. alert('Sorry, you have reached the maximum number of images per listing');
  33. }
  34. }



Czego to wina jak to naprawić ?

Ten post edytował fantek 6.02.2014, 12:00:45
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
fantek
post
Post #2





Grupa: Zarejestrowani
Postów: 51
Pomógł: 0
Dołączył: 9.10.2010

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


  1. <script type="text/javascript">
  2. var photoIndex = 0;
  3. function gebi(id) { return document.getElementById(id); }
  4. function ce(name) { return document.createElement(name); }
  5. function re(id) {
  6. var e = gebi(id);
  7. e.parentNode.removeChild(e);
  8. var max = 7;
  9. var num_img = $('input[name="photos[]"]').size() + $("a.delete").size();
  10. if((max!=0 && num_img<=max) || max==0) {
  11. $('#addPhotoLink').removeClass('hide_box');
  12. }
  13. }
  14. function addNewPhoto() {
  15. var max = 7;
  16. var num_img = $('input[name="photos[]"]').size() + $("a.delete").size();
  17. if((max!=0 && num_img<max) || max==0) {
  18. var id = 'p-' + photoIndex++;
  19.  
  20. var i = ce('input');
  21. i.setAttribute('type', 'file');
  22. i.setAttribute('name', 'photos[]');
  23.  
  24. var a = ce('a');
  25. a.style.fontSize = 'x-small';
  26. a.style.paddingLeft = '10px';
  27. a.setAttribute('href', '#');
  28. a.setAttribute('divid', id);
  29. a.onclick = function() { re(this.getAttribute('divid')); return false; }
  30. a.appendChild(document.createTextNode('Remove'));
  31.  
  32. var d = ce('div');
  33. d.setAttribute('id', id);
  34. d.setAttribute('style','padding: 4px 0;')
  35.  
  36. d.appendChild(i);
  37. d.appendChild(a);
  38.  
  39. gebi('photos').appendChild(d);
  40. if( num_img +1 == max){
  41. $('#addPhotoLink').addClass('hide_box');
  42. }
  43.  
  44. } else {
  45. alert('Sorry, you have reached the maximum number of images per listing');
  46. }
  47. }
  48. // Listener: automatically add new file field when the visible ones are full.
  49. $(document).ajaxSuccess(function () {
  50. setInterval("add_file_field()", 250);
  51. });
  52. /**
  53. * Timed: if there are no empty file fields, add new file field.
  54. */
  55. function add_file_field() {
  56. //jesli jestesmy na dodawaniu produktu
  57. if($('.add_item').length > 0){
  58. var count = 0;
  59. $('input[name="photos[]"]').each(function(index) {
  60. if ( $(this).val() == '' ) {
  61. count++;
  62. }
  63. });
  64. var max = 7;
  65. var num_img = $('input[name="photos[]"]').size() + $("a.delete").size();
  66. if (count == 0 && (max==0 || (max!=0 && num_img<max))) {
  67. addNewPhoto();
  68. }
  69. }
  70. }
  71.  
  72.  
  73.  
  74. </script>


Dokładnie cały kod skryptu.

Ale czemu w chromie i innych przeglądarkach normalnie działa bez errorów a w IE wywala tego errora ? Czego to może być przyczyna ? (IMG:style_emoticons/default/sad.gif)
Go to the top of the page
+Quote Post
PrinceOfPersia
post
Post #3





Grupa: Zarejestrowani
Postów: 717
Pomógł: 120
Dołączył: 18.04.2009

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


pod którą wersję IE dostosowujesz?

Google wyrzuca coś takiego: http://webbugtrack.blogspot.com/2007/08/bu...lways-work.html
nie wiem jak się to ma do tego, ale to jest właśnie przyczyna, żeby nie wspierać starszych wersji IE..
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: 11.10.2025 - 17:20