Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [ajax] onsubmit nie działa pod ie
Jim
post 3.06.2006, 11:47:24
Post #1





Grupa: Zarejestrowani
Postów: 111
Pomógł: 0
Dołączył: 27.07.2005

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


Witam,
mam problem z przesyłaniem formularza. Pod FF działa poprawnie, ale w IE już nie - po kliknięciu "dodaj" wyświetlana jest odpowiedź w xml'u.

w tagu <form> jest atrybut onSubmit="validate(this); return false;"
funkcja validate() sprawdza poprawnośc danych w formularzu i jeśli jest ok wywoływana jest funkcja sendform korzystająca z advAJAX'a.

oto funkcje:
  1. function sendform(form) {
  2. advAJAX.submit(form, {
  3. onSuccess : function(obj) {
  4.  
  5. var result = xml2array(obj.responseXML);
  6.  
  7. if (result["result"] == 1) {
  8. document.getElementById('addform').innerHTML = '';
  9. msg = document.getElementById("msg");
  10. msg.childNodes[0].data = "Dziękuję za zgłoszenie strony";
  11. msg.style.color = "green";
  12.  
  13. } else {
  14. msg = document.getElementById("msg");
  15. msg.childNodes[0].data = "Wystąpił błąd, spróbuj ponownie.";
  16. msg.style.color = "red";
  17. }
  18.  
  19. },
  20.  
  21. onError : function(obj) {
  22. msg = document.getElementById("msg");
  23. msg.childNodes[0].data = "Wystąpił błąd połączenia: " + obj.status;
  24. msg.style.color = "red";
  25. },
  26.  
  27. onLoading : function() {
  28. document.getElementById("submitlabel").innerHTML = '<img src="images/indicator.gif" height="16" width="16" border="0">';
  29. btn = document.getElementById("submit");
  30. btn.disabled = true; },
  31.  
  32. onFinalization : function() {
  33. document.getElementById("submitlabel").innerHTML = ''; }
  34. });
  35. }
  36.  
  37. function validate(form) {
  38. addform = document.getElementById("addform");
  39. titleLen = addform.title.value.length;
  40. descriptionLen = addform.description.value.length;
  41. urlLen = addform.url.value.length;
  42. tagsLen = addform.tags.value.length;
  43. emailLen = addform.email.value.length;
  44. email = addform.email.value;
  45.  
  46. msg = document.getElementById("msg");
  47. msg.style.color = "red";
  48.  
  49. if (titleLen <= 4) {
  50. msg.childNodes[0].data = "Za krótki tytuł strony (minimum 5 znaków).";
  51.  
  52. } else if (urlLen <= 12) {
  53. msg.childNodes[0].data = "Za krótki adres strony (pamiętaj o http://).";
  54.  
  55. } else if (descriptionLen <= 90) {
  56. msg.childNodes[0].data = "Za krótki opis strony (minimum 90 znaków).";
  57.  
  58. } else if (tagsLen <= 6) {
  59. msg.childNodes[0].data = "Za mało tagów.";
  60.  
  61. } else if (!email.match('^.+@.+..+$')) {
  62. msg.childNodes[0].data = "Niepoprwany email.";
  63.  
  64. } else {
  65. msg.childNodes[0].data = " ";
  66. sendform(form);
  67. }
  68.  
  69. }


z góry dziękuję za pomoc winksmiley.jpg

Ten post edytował Jim 3.06.2006, 12:05:15
Go to the top of the page
+Quote Post
yaro
post 3.06.2006, 16:25:55
Post #2





Grupa: Zarejestrowani
Postów: 160
Pomógł: 4
Dołączył: 22.04.2006
Skąd: Kraków

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


Może wywal to z form onSubmit tą walidacje i sprawdzaj ją w funkcji sendform(), ja robiłem w mniej więcej taki sposób:

Kod
function sendform(form) {
var blad = 0;
if (d.length<=1) blad = 1; //sprawdzanie formularza
itd...

if (blad != 0) {

advAJAX.submit(form, {
onSuccess : function(obj) {
......
}
}
}

}


--------------------
Go to the top of the page
+Quote Post
Jim
post 4.06.2006, 22:23:04
Post #3





Grupa: Zarejestrowani
Postów: 111
Pomógł: 0
Dołączył: 27.07.2005

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


no, metodą 1000 prób i błędów poprawiłem funkcje i wszystko działa jak należy. Oto działające funkcje

  1. function sendform() {
  2. advAJAX.submit( document.getElementById("addform"), {
  3. onSuccess : function(obj) {
  4.  
  5. var result = xml2array(obj.responseXML);
  6.  
  7. if (result["result"] == 1) {
  8. document.getElementById("addform").innerHTML = "";
  9. document.getElementById("msg").innerHTML = "Dziękuję za zgłoszenie strony.";
  10. document.getElementById("msg").style.color = "green";
  11.  
  12. } else {
  13. document.getElementById("msg").innerHTML = "Wystąpił błąd, spróbuj ponownie.";
  14. document.getElementById("msg").style.color = "red";
  15. }
  16. document.getElementById("submit").disabled = false;
  17. },
  18.  
  19. onError : function(obj) {
  20. document.getElementById("msg").innerHTML = "Wystąpił błąd połączenia: " + obj.status;
  21. document.getElementById("msg").style.color = "red";
  22. },
  23.  
  24. onLoading : function() {
  25. document.getElementById("submitlabel").innerHTML = '<img src="images/indicator.gif" height="16" width="16" border="0">';
  26. document.getElementById("submit").disabled = true;
  27. },
  28.  
  29. onFinalization : function() {
  30. document.getElementById("submitlabel").innerHTML = " ";
  31. }
  32. });
  33.  
  34. }
  35.  
  36. function validate() {
  37. var formularz = document.getElementById("addform");
  38. var titleLen = document.getElementById("title").value.length;
  39. var urlLen = document.getElementById("url").value.length;
  40. var tagsLen = document.getElementById("tags").value.length;
  41. var emailLen = document.getElementById("email").value.length;
  42. var email = document.getElementById("email").value;
  43.  
  44. var msg = document.getElementById("msg");
  45. msg.style.color = "red";
  46.  
  47. if (titleLen <= 4) {
  48. msg.innerHTML = "Za krótki tytuł strony (minimum 5 znaków).";
  49.  
  50. } else if (urlLen <= 12) {
  51. msg.innerHTML = "Za krótki adres strony (pamiętaj o http://).";
  52.  
  53. } else if (tagsLen <= 6) {
  54. msg.innerHTML = "Za mało tagów.";
  55.  
  56. } else if (!email.match('^.+@.+..+$')) {
  57. msg.innerHTML = "Niepoprwany email.";
  58.  
  59. } else {
  60. sendform();
  61. }
  62.  
  63. }


...to tak jakby ktoś kiedyś szukał winksmiley.jpg
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: 28.04.2024 - 16:23