Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [js] skrypt php sie wykonuje chociaz nie powinien.
gigzorr
post 24.08.2010, 14:50:43
Post #1





Grupa: Zarejestrowani
Postów: 652
Pomógł: 47
Dołączył: 6.02.2010
Skąd: Radom

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


witam , mam skrypt , ktory sprawdza czy wprowadzone znaki to 0-9 , a-z , i wywala blad , i wszystko jest ok , ale po kliknieciu ok , wykonuje sie action , chociaz nie powinno.
Oto skrypt:
  1. <script type='text/javascript'>
  2. // If the element's string matches the regular expression it is numbers and letters
  3. function isAlphanumeric(elem, helperMsg){
  4. var alphaExp = /^[0-9a-zA-Z]+$/;
  5. var error = false;
  6. if(elem.value.match(alphaExp)){
  7. error = true;
  8. }else{
  9. alert(helperMsg);
  10. elem.focus();
  11. error = true;
  12. }
  13.  
  14.  
  15.  
  16. if (error) {
  17. return false;
  18. }
  19. }
  20. </script>

A tak jest wywolywany:
  1. <input type="submit" onclick="isAlphanumeric(document.getElementById('nazwa'), 'Dozwolone znaki: A-Z,0-9 !')"
  2. value="bleble" style="width: 140px;font-family:Tahoma;margin-top:-5px;" />
Go to the top of the page
+Quote Post
wookieb
post 24.08.2010, 14:57:15
Post #2





Grupa: Moderatorzy
Postów: 8 989
Pomógł: 1550
Dołączył: 8.08.2008
Skąd: Słupsk/Gdańsk




  1. onclick="return isAlphanumeric(document.getElementById('nazwa'), 'Dozwolone znaki: A-Z,0-9 !')"


--------------------
Go to the top of the page
+Quote Post
gigzorr
post 24.08.2010, 15:00:07
Post #3





Grupa: Zarejestrowani
Postów: 652
Pomógł: 47
Dołączył: 6.02.2010
Skąd: Radom

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


hm , ale wtedy submit nie dziala jak sa dobre dane?

nvm. zrobilem to stosujac onchange przypisujac do inputa.

Ten post edytował gigzorr 24.08.2010, 15:02:40
Go to the top of the page
+Quote Post
wookieb
post 24.08.2010, 15:03:41
Post #4





Grupa: Moderatorzy
Postów: 8 989
Pomógł: 1550
Dołączył: 8.08.2008
Skąd: Słupsk/Gdańsk




Bo musisz na samym samiutkim końcu funkcji dać return true


--------------------
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 Wersja Lo-Fi Aktualny czas: 5.07.2025 - 14:44