Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [js] Zabezpieczenie przed wyslaniem pustego formularz
Kemot1000
post
Post #1





Grupa: Zarejestrowani
Postów: 12
Pomógł: 0
Dołączył: 3.02.2007

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


mam formularz w ktorym sa 2 przyciski i 2 pola tekstowe chcialbym zeby niemzliwym bylo wyslanie formularza ktory nie zawieralby tekstu we wszystkich. Tyle mam:

  1. <script language="javascript" type="text/javascript">
  2. <!--
  3. function verify(Form1)
  4. {
  5. for (i = 0; i < Form1.length; i++)
  6. {
  7. var field = Form1.elements[i];
  8. if (field.type == "text" || field.type == "textarea" && field.value == "")
  9. {
  10. return false;
  11. }
  12. }
  13. return true;
  14. }
  15. -->
  16. <form name="Form1" method=post>
  17. <input type="text" name=NewText size=4 maxlength=4>
  18. <input type="button" value="Button1" name=button1 onClick="return check1();" />
  19. <input type=\"text\" name=\"NewText1\">
  20. <input type="button" value="Button2" name=button2 onClick="return check2();">
  21. </form>
  22.  
  23. <script language=javascript TYPE="text/javascript">
  24. <!--
  25.  
  26. function check1()
  27. { if (verify(Form1))
  28. {
  29. document.Form1.action = "http://anypage.com";
  30. document.Form1.target = "_blank";
  31. document.Form1.submit();
  32. return true;}
  33. else
  34. {
  35. alert("Please fill out all obligatory fields");
  36. return false;
  37. }
  38. }
  39.  
  40. function check2()
  41. { if (verify(Form1))
  42. {
  43. document.Form1.action = "test.php";
  44. document.Form1.target = "_blank";
  45. document.Form1.submit();
  46. return true; }
  47. else
  48. {
  49. alert("Please fill out all obligatory fields");
  50. return false;
  51. }
  52. }
  53. --> </script>



i za kazdym razem jak wysylam dostaje alert ze pola sa nie wypelnione nie wazne czy sa czy nie? ktos wie moze gdzie jest blad o czym zapomnialem??
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: 3.10.2025 - 12:13