Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [jquery]jquery form confirm
Forum PHP.pl > Forum > XML, AJAX
kilofmar
Witam.

Mam pewien problem z wysłaniem formularza z pluginem jquery.form.js
Chcę wysłać formularz ale przed wysłaniem ma pojawić się okno z możliwością zaznaczenia dodatkowy opcji.
I okno pojawia mi się, ale formularz wysyła się zanim nacisnę Wykonaj.
Jak wstrzymać wysyłanie formularza do momentu naciśnięcia tego przycisku.

Wszystkie pliki do pobrania TU

  1.  
  2.  
  3. //###################################
  4. function Dialog(){
  5.  
  6. $( "#dialog-form" ).dialog({
  7. autoOpen: true,
  8. height: 300,
  9. width: 350,
  10. modal: true,
  11. buttons: {
  12. "Wykonaj": function() {
  13.  
  14. $('#poz1').val('2');
  15. $('#poz1').val('1');
  16. $('#poz3').val('1');
  17. $( this ).dialog( "close" );
  18.  
  19. },
  20. "Rezygnuj": function() {
  21. $( this ).dialog( "close" );
  22. }
  23. },
  24. close: function() {
  25. $( this ).dialog( "close" );
  26. }
  27. });
  28. }
  29.  
  30.  
  31. function Zapisz(){
  32.  
  33. var options = {
  34. target: '#status', // target element(s) to be updated with server response
  35. beforeSubmit: Dialog, // pre-submit callback
  36. success: showResponse // post-submit callback
  37. };
  38.  
  39. // bind to the form's submit event
  40. $('#opcje').ajaxSubmit(options);
  41. return false;
  42.  
  43. }
  44.  
  45. function showResponse(responseText, statusText, xhr, $form) {
  46. alert(responseText);
  47. }
  48. </script>
  49.  
  50.  
  51.  
  52.  
  53.  
  54. <div id="dialog-form" title="Dodatkowe opcję" style="display: none;">
  55. <p class="validateTips">Zaznacz odpowiednie opcję</p>
  56.  
  57. <form>
  58. <label for="name">Pozycja1:<input type="checkbox" name="poz1" id="poz1" /></label>
  59. <label for="name">Pozycja1:<input type="checkbox" name="poz2" id="poz2" /></label>
  60. <label for="name">Pozycja1:<input type="checkbox" name="poz3" id="poz3" /></label>
  61.  
  62. </form>
  63. </div>
  64.  
  65. <form action="dane.php" method="post" id="opcje">
  66. <input type="hidden" name="frek" >
  67. <input type="hidden" name="oceny" >
  68. <input type="hidden" name="grupy" >
  69.  
  70. imię:<input type="text" name="imie"><br>
  71. coś:<input type="text" name="cos">
  72.  
  73. <input type="button" value="usun" onclick="Zapisz();" >
  74. </form>
  75.  
  76. <div id="status"></div>
  77.  
rocktech.pl
Witam.

event.preventDefault

[JAVASCRIPT] pobierz, plaintext
  1. function Zapisz(event){
  2. event.preventDefault();
  3. ...
[JAVASCRIPT] pobierz, plaintext
kilofmar
Coś mi to nie wychodzi, nigdy nie stonowałem tej funkcji.
Zmieniłem te linie ale nie działa.

  1.  
  2. $("#zapisz").click(function(event) {
  3. event.preventDefault();
  4.  
  5. var options = {
  6. target: '#status', // target element(s) to be updated with server response
  7. beforeSubmit: Dialog, // pre-submit callback
  8. success: showResponse // post-submit callback
  9. };
  10.  
  11. // bind to the form's submit event
  12. $('#opcje').ajaxSubmit(options);
  13. return false;
  14.  
  15. });


I
  1. <form action="dane.php" method="post" id="opcje">
  2. <input type="hidden" name="frek" >
  3. <input type="hidden" name="oceny" >
  4. <input type="hidden" name="grupy" >
  5.  
  6. imię:<input type="text" name="imie"><br>
  7. coś:<input type="text" name="cos">
  8.  
  9. <input type="button" value="usun" id="zapisz" >
  10. </form>
rocktech.pl
Wywal return false z funkcji.

Pytanie co nie działa?

Opdal Firebuga w FF albo Dragonfly w Operze. Otwórz zakładkę konsola lub błędy.

[JAVASCRIPT] pobierz, plaintext
  1. $("#zapisz").click(function(event) {
  2. event.preventDefault();
  3.  
  4. var options = {
  5. target: '#status', // target element(s) to be updated with server response
  6. beforeSubmit: Dialog, // pre-submit callback
  7. success: showResponse // post-submit callback
  8. };
  9.  
  10. // bind to the form's submit event
  11. $('#opcje').ajaxSubmit(options);
  12. console.log('ajaxSubmit');
  13.  
  14. });
[JAVASCRIPT] pobierz, plaintext
kilofmar
Witam.

Usunąłem ten return false ale nadal wysyła mi ten formularz zanim nacisnę Wykonaj w oknie.
On nie zwraca żadnego błędu.
Umieściłem skrypt pod adresem http://marek.kilofmar.com.pl/dialog/index.html
rocktech.pl
Hej.

Błędy są.

Uncaught exception: RangeError: Maximum recursion depth exceeded

[JAVASCRIPT] pobierz, plaintext
  1. function Dialog(){
  2.  
  3. $( "#dialog-form" ).dialog({
  4. autoOpen: true,
  5. height: 300,
  6. width: 350,
  7. modal: true,
  8. buttons: {
  9. "Wykonaj": function() {
  10.  
  11. $('#poz1').val('2');
  12. $('#poz1').val('1');
  13. $('#poz3').val('1');
  14. $( this ).dialog( "close" );
  15.  
  16. },
  17. "Rezygnuj": function() {
  18. $( this ).dialog( "close" );
  19. }
  20. },
  21. close: function() {
  22. $( this ).dialog( "close" ); //Maximum recursion depth exceeded
  23. //Tu zamknij tego modala a nie wywołuj funkcji zamykającej w nieskończoność
  24. }
  25. });
  26. }
[JAVASCRIPT] pobierz, plaintext
kilofmar
Faktycznie był błąd, dzięki.
Usunąłem ta funkcje "close" ale niestety nadal wysyła mi formularz zaraz po włączeniu okna.

  1.  
  2. //###################################
  3. function Dialog(){
  4.  
  5. $( "#dialog-form" ).dialog({
  6. autoOpen: true,
  7. height: 300,
  8. width: 350,
  9. modal: true,
  10. buttons: {
  11. "Wykonaj": function() {
  12.  
  13. $('#poz1').val('2');
  14. $('#poz1').val('1');
  15. $('#poz3').val('1');
  16. $( this ).dialog( "close" );
  17.  
  18. },
  19. "Rezygnuj": function() {
  20. $( this ).dialog( "close" );
  21. }
  22. }
  23. });
  24. }
  25.  
  26.  
  27. $("#zapisz").click(function(event) {
  28. event.preventDefault();
  29.  
  30. var options = {
  31. target: '#status', // target element(s) to be updated with server response
  32. beforeSubmit: Dialog, // pre-submit callback
  33. success: showResponse // post-submit callback
  34. };
  35.  
  36. // bind to the form's submit event
  37. $('#opcje').ajaxSubmit(options);
  38. console.log('ajaxSubmit');
  39.  
  40. });
  41.  
  42. function showResponse(responseText, statusText, xhr, $form) {
  43. alert(responseText);
  44. }
  45.  


Udało mi się to rozwiązać wiedź wstawiam poprawny kod

  1.  
  2.  
  3.  
  4. $("#zapisz").click(function(event) {
  5. $( "#dialog-form" ).dialog({
  6. autoOpen: true,
  7. height: 300,
  8. width: 350,
  9. modal: true,
  10. buttons: {
  11. "Wykonaj": function() {
  12.  
  13. $('#poz1').val('2');
  14. $('#poz1').val('1');
  15. $('#poz3').val('1');
  16. //opcje do formularza
  17. var options = {
  18. target: '#status', // target element(s) to be updated with server response
  19. // pre-submit callback
  20. success: showResponse // post-submit callback
  21. };
  22. // i tu wysylamy form
  23. $('#opcje').ajaxSubmit(options);
  24. $( this ).dialog( "close" );
  25.  
  26. },
  27. "Rezygnuj": function() {
  28. $( this ).dialog( "close" );
  29. }
  30. }
  31. });
  32.  
  33. });
  34.  
  35.  
  36.  
  37. function showResponse(responseText, statusText, xhr, $form) {
  38. alert(responseText);
  39. }
  40. </script>
  41.  
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.