After learning about jQuery and the whole AJAX thing, I got very excited. I decided to completely replace my forms with just input fields. And the data is sent to the server when the '<'input type="button" /'>' clicked.
// JavaScript
function submit() {
removeInfo();
btn = $('#button');
$('#button').replaceWith('<img id="theimage" src="/images/ajax-loader.gif" />');
$.post('/jlogin',
{
username: $('#username').val(),
password: $('#password').val(),
captcha: $('#captcha').val()
},
function (data) {
if (data.status == 'SUCCESS') {
window.location = '/successfullogin';
}
else {
$(data.errorInput).addClass('inputerror');
$(data.errorInput).focus();
$('#spanFailed').text(data.info);
appear('#divFailed');
if (data.errorInput == '#captcha') {
captchaimage.src = '/captcha?i=2' + Math.floor(Math.random() * 11);
}
$('#theimage').replaceWith(btn);
}
},
'json'
);
}
<!-- HTML -->
<div id="divFailed" class="error" style="display:none; width:250px; height:25px;">
<span id="spanFailed" class="spanerror">
</span>
<br />
</div>
<br />
Username:
<input type="text" id="username" />
<!-- and other inputs here -->
<input type="button" id="button" onclick="submit()" value="Login" >
So the problem is that if the user has no JavaScript enabled, s/he won't be able to use my web application. Also it's impossible to let browsers remember passwords.
I heard about serializing forms with JavaScript. But how would I be able to use these fancy red alerts when using forms without JavaScript?
So basically I want to have the same functionality but with forms.