Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Przekierowanie strony w js
pero
post
Post #1





Grupa: Zarejestrowani
Postów: 91
Pomógł: 0
Dołączył: 17.02.2007

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


Witam
Mam problem z wymuszeniem przekierowania strony.
W zdarzeniu onload w js dodaje do wszystkich formularzy na stronie zdarzenie które powinno przekierować stronę na adres z przyjaznym linkiem. Sama funkcja wykonuje się jednak po niej i tak następuje wykonanie skryptu przez serwer i do samego przekierowania w js defakto nie dochodzi. Funkcje wyglądają tak:
  1. function form_link()
  2. {
  3. var E = document.getElementsByTagName('form');
  4.  
  5. for (i=0; i<E.length; i++)
  6. {
  7. E[i].onsubmit = function(){return map_link(this);}
  8. }
  9. }
  10.  
  11. function map_link(E)
  12. {
  13. var ac,mode,id,page,liczba,index;
  14. ac = E.ac.value;
  15. mode = E.mode.value;
  16. id = E.id.value;
  17. page = E.page.value;
  18. liczba = E.liczba.value;
  19. index = E.index.value;
  20.  
  21. window.location.href = 'http://www.google.pl';
  22.  
  23. }

Możecie pomóc? Jak zrobić zeby wykonało się przekierowanie w js a zdarzenie formularza nie bylo juz przechwytywane przez serwer ?
Go to the top of the page
+Quote Post
Zajec
post
Post #2





Grupa: Zarejestrowani
Postów: 1 086
Pomógł: 8
Dołączył: 10.12.2003

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


Włączyłeś konsolę JS w przeglądarce? Powinien wyskoczyć błąd konkretny z numerem linii.

Może któreś przypisanie wartości wewnątrz map_link się nie udaje?
Go to the top of the page
+Quote Post
pero
post
Post #3





Grupa: Zarejestrowani
Postów: 91
Pomógł: 0
Dołączył: 17.02.2007

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


tak włączyłem ale nie wyświetla się żadna informacja o błędzie, wszystko jest ok, a sie nie wykonuje tak jak powinno sad.gif
Go to the top of the page
+Quote Post
Zajec
post
Post #4





Grupa: Zarejestrowani
Postów: 1 086
Pomógł: 8
Dołączył: 10.12.2003

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


To zrób sobie mały debugging smile.gif
Kod
function form_link()
{
alert('starting form_link');
var E = document.getElementsByTagName('form');
alert('found '.E.length.' forms');
for (i=0; i<E.length; i++)
{
E[i].onsubmit = function(){alert('you clicked me!'); return map_link(this);}
}
alert('applied to every form');
}

function map_link(E)
{
alert('starting map_link');
var ac,mode,id,page,liczba,index;
ac = E.ac.value;
mode = E.mode.value;
id = E.id.value;
page = E.page.value;
liczba = E.liczba.value;
index = E.index.value;
alert('reidirecting you');
window.location.href = 'http://www.google.pl';
alert('should this be executed?');
}


Ten post edytował Zajec 14.07.2008, 16:59:27
Go to the top of the page
+Quote Post
pero
post
Post #5





Grupa: Zarejestrowani
Postów: 91
Pomógł: 0
Dołączył: 17.02.2007

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


przechodzi przez wszystkie alerty.
nawet ostatni :/
alert('should this be executed?');


moze ja jeszcze podam sam kod formularza.
Moze to pomoze.

  1. <form action="#" method="get">
  2. <li class="li_form_zp">ZNAJDŹ PRACOWNIKA</li>
  3. <input type="hidden" name="ac" value="szukaj" />
  4. <select name="mode">
  5. <option value="0">Wybierz rejon</option>
  6. </select>
  7.  
  8. <select name="id">
  9. <option value="1">Dowolna Branża</option>
  10. </select>
  11. <input type="text" name="page" value=" Szukaj " />
  12. <input type="submit" value="szukaj" />
  13.  
  14. </form>
Go to the top of the page
+Quote Post
batman
post
Post #6





Grupa: Moderatorzy
Postów: 2 921
Pomógł: 269
Dołączył: 11.08.2005
Skąd: 127.0.0.1




Po window.location.href dodaj return false i powinno działać. Poza tym polecam zmienić nazwę zmiennej E. Zazwyczaj przez e (małe e) oznacza się zdarzenie.


--------------------
I would love to change the world, but they won't give me the source code.
My software never has bugs. It just develops random features.
Go to the top of the page
+Quote Post
pero
post
Post #7





Grupa: Zarejestrowani
Postów: 91
Pomógł: 0
Dołączył: 17.02.2007

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


nie pomaga return false.
Go to the top of the page
+Quote Post
batman
post
Post #8





Grupa: Moderatorzy
Postów: 2 921
Pomógł: 269
Dołączył: 11.08.2005
Skąd: 127.0.0.1




Mój błąd. Nie w tym miejscu powinno być return false.
Kod
E[i].onsubmit = function(){map_link(this); return false;}


--------------------
I would love to change the world, but they won't give me the source code.
My software never has bugs. It just develops random features.
Go to the top of the page
+Quote Post
pero
post
Post #9





Grupa: Zarejestrowani
Postów: 91
Pomógł: 0
Dołączył: 17.02.2007

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


dzieki. teraz dziala smile.gif
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 - 20:19