Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript]nie widzi funkcji
tog
post
Post #1





Grupa: Zarejestrowani
Postów: 93
Pomógł: 4
Dołączył: 1.12.2009
Skąd: lublin

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


witam,

mam problem z wywolaniem funckji
funkcja sprawdza czy user wpisal wszystkei dane do formularza kontaktowego, jesli nie to wywala na ekran bledy i nie wysyla formularza


  1.  
  2. <script type="text/javascript" src="javascript/functions.js"></script>
  3. </head>
  4.  



  1.  
  2. <div>
  3. <span class="headline">.contact</span><br /><br />
  4. <form action="#" method="post" onsubmit="return validate_contact()">
  5.  
  6. <span class="field_name">Your name</span><br />
  7. <input type="text" name="name" id="name" class="contact" style="border: 1px solid #ff2a00;" />
  8. <span class="field_error" id="field_error_name"></span><br />
  9.  
  10. <span class="field_name">Your e-mail</span><br />
  11. <input type="text" name="mail" id="mail" class="contact" />
  12. <span class="field_error" id="field_error_mail"></span><br />
  13.  
  14. <span class="field_name">message</span><br />
  15.  
  16. <textarea name="message" id="message" cols="0" rows="0" class="contact"></textarea>
  17. <span class="field_error" id="field_error_message"></span><br />
  18.  
  19. <button class="contact">send</button>
  20. </form>
  21. </div>
  22.  
  23.  


  1.  
  2. function validate_contact()
  3. {
  4. var name = document.getElementById('nick').value;
  5. var mail = document.getElementById('mail').value;
  6. var message = document.getElementById('message').value;
  7.  
  8. ret = 0
  9.  
  10. if(name == ''){document.getElementById('field_error_name').innerHTML = 'You must give your name.'}
  11. else{document.getElementById('field_error_name').innerHTML = ''; ++ret}
  12.  
  13. if(mail == ''){document.getElementById('field_error_mail').innerHTML = 'You must give your e-mail address.'}
  14. else{document.getElementById('field_error_mail').innerHTML = ''; ++ret}
  15.  
  16. if(message == ''){document.getElementById('field_error_message').innerHTML = 'You must interline message content.'}
  17. else{document.getElementById('field_error_message').innerHTML = ''; ++ret}
  18.  
  19.  
  20. return false
  21. }
  22.  


funkcja jest neiskonczona, zmienna ret jest nieistotna

pierwszym bledem jest to, ze formularz sie wysyla, mimo, ze zwracam 'return false'
funkcje ta napisalem wczesniej i dzialala poprawnie, pozniej ja troche edytowalem i juz nie dziala
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
darko
post
Post #2





Grupa: Zarejestrowani
Postów: 2 885
Pomógł: 463
Dołączył: 3.10.2009
Skąd: Wrocław

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


po ++ret daj średnik
a gdzie Ty w ogóle zwracasz w tej funkcji true ?
co pokazuje konsola błędów?
gdzie na formularzu występuje element o id == 'nick' ?
Go to the top of the page
+Quote Post
tog
post
Post #3





Grupa: Zarejestrowani
Postów: 93
Pomógł: 4
Dołączył: 1.12.2009
Skąd: lublin

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


wydaje misie, ze bez srednikow powinno dzialac (IMG:style_emoticons/default/snitch.gif)

eot
poprzednio pole nazywlo sie 'nick', teraz nazwalem je 'name' i przeoczylem zmiane w tym miejscu

dzieki za pomoc (IMG:style_emoticons/default/winksmiley.jpg)

PS: wczesniej bylo true
tylko usunalem ta czesc aby wykluczyc blad w tym miejscu

Ten post edytował tog 30.12.2009, 18:48:32
Go to the top of the page
+Quote Post

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: 23.08.2025 - 13:52