Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [JavaScript] Jak polaczyc dwie funkcjie (funkcja w opcji switch)
Forum PHP.pl > Forum > Przedszkole
Ciosek
Witam.

Chcialbym dodac event tracker z google analytics do funkcji switch.

Dzialajcy skrypt umieszczaony bezposrednio w formularzu:
  1. <input type="button" value="test" onClick="_gaq.push(['_trackEvent', 'Form', 'Click', 'value 1']);"/>


Dzialaacy skrypt pobierany z osobnego pliku:
  1. RequestForm.prototype.setButtonText = function()
  2. {
  3. var sText = '';
  4. switch( this._currentPage )
  5. {
  6. case 0:
  7. sText = 'Button 1';
  8. break;
  9. case 1:
  10. sText = 'Button 2';
  11. break;
  12. case 2:
  13. sText = 'Button 3';
  14. break;
  15. case 3:
  16. sText = 'Button 4';
  17. break;
  18. case 4:
  19. sText = 'Button 5';
  20. break;
  21. default:
  22. sText = 'dalej';
  23. break;
  24. }
  25.  
  26. this._submitbutton.value = sText;
  27. }


Teraz chcialbym zrobic to tak:
gdy _currentPage = 0 to _gaq.push(['_trackEvent', 'Form', 'Click', 'value 0']);
gdy _currentPage = 1 to _gaq.push(['_trackEvent', 'Form', 'Click', 'value 1']);
itd...


Probowalem cos takiego:
  1. RequestForm.prototype.setButtonText = function()
  2. {
  3. var sText = '';
  4. switch( this._currentPage )
  5. {
  6. case 0:
  7. sText = 'Button 1';
  8. _currentPage = 0 to _gaq.push(['_trackEvent', 'Form', 'Click', 'value 0']);
  9. break;
  10. case 1:
  11. sText = 'Button 2';
  12. break;
  13. case 2:
  14. sText = 'Button 3';
  15. break;
  16. case 3:
  17. sText = 'Button 4';
  18. break;
  19. case 4:
  20. sText = 'Button 5';
  21. break;
  22. default:
  23. sText = 'dalej';
  24. break;
  25. }
  26.  
  27. this._submitbutton.value = sText;
  28. }

Jednak to nie dziala.

Wielkie dzieki z gory za pomoc
Daimos
Poważnie wkleiłeś to w takiej postaci?
  1. _currentPage = 0 to _gaq.push(['_trackEvent', 'Form', 'Click', 'value 0']);

Zapomniałeś chyba jeszcze dodać na początku "gdy" smile.gif
Ciosek
Nie. Problwalem edytowac post ale cos sie zepsulo i nie dalem rady:

Taki kod wkleilem:

do case '0':

  1. _gaq.push(['_trackEvent', 'Form', 'Click', 'value 0']);


Czyli:
  1. RequestForm.prototype.setButtonText = function()
  2. {
  3. var sText = '';
  4. switch( this._currentPage )
  5. {
  6. case 0:
  7. sText = 'Button 1';
  8. _gaq.push(['_trackEvent', 'Form', 'Click', 'value 0']);
  9. break;
  10. case 1:
  11. sText = 'Button 2';
  12. break;
  13. case 2:
  14. sText = 'Button 3';
  15. break;
  16. case 3:
  17. sText = 'Button 4';
  18. break;
  19. case 4:
  20. sText = 'Button 5';
  21. break;
  22. default:
  23. sText = 'dalej';
  24. break;
  25. }
  26.  
  27. this._submitbutton.value = sText;
  28. }
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.