Mam taką funkcję:
function registration() {
advAJAX.assign(document.getElementById("registration"), {
onInitialization : function() {
document.getElementById("result").style.visibility = "visible";
document.getElementById("result").style.background = "#ff0000";
document.getElementById("result").style.color = "#ffffff";
document.getElementById("result").innerHTML = "Trwa laczenie...";
},
onSuccess : function(obj) {
if (obj.responseText == "success") {
document.getElementById("result").style.background = "#94FF29";
document.getElementById("result").style.color = "#000000";
document.getElementById("result").innerHTML = "Trwa laczenie...";
} else {
/*
* Tutaj chcialbym dodac obsluge kolorowania poszczegolnych inputow,
* ktore sa zle wypelnione. Jakies pomysly?
*/
}
}
});
}
A formularz wygląda mniej więcej tak (podaję kilka pól dla przykładu):
<div id="result" style="visibility: hidden;"></div> <form action="registration.php" method="post" id="registration"> <td width="100">adres e-mail:
</td> <td><input type="text" name="email" id="email" /></td> <td valign="top">hasło:
</td> <td><input type="password" name="pass1" id="pass1" /></td> <td><input type="password" name="pass2" id="pass2" /></td> <td align="right"><input type="submit" value="Zarejestruj się" /></td>
Plik
registration.php generuje oczywiście odpowiednie informacje zwrotne. Ale co się dzieje kiedy użytkownik ma wyłączoną obsługę JavaScript w przeglądarce? Otóz formularz wykona się tradycyjną drogą i użytkownik zostanie przeniesiony do
registration.php, który wyświetli mu jednak niestety krótką informację zwrotną - nie zaś stronę HTML.
Jak zrobić, żeby submit działał tylko przy włączonej obsłudze JavaScript?<input type="button" value="Zarejestruj się" onclick="document.registration.submit();" />
działa, ale wtedy kod AJAX nie zostanie zaimplementowany.