Usage example
<script type="text/javascript" src="../scripts/prototype.js"></script>
<script type="text/javascript">
var progressBar;
/**//*
* Function: admin login
*/
function UserLogin()
{
//Verify page controls
var checkform = new CheckForm();
if(!checkform.checkForm(document.getElementById('formLogin'))) return false;
//Start submitting data
progressBar = new ProgressBar();
progressBar.SetStatus("Sending data to server.");
var url = "../admin.do";
var pars = "action=Login&username=" + $F('username') + "&password=" + $F('password') + "&rnd=" +$F('rnd');
var myAjax = new Ajax.Request(
url,
{method: 'post', parameters: pars, onComplete: UserLogin_CallBack}
);
}
/**//*
* Function: admin login - CallBack
*/
function UserLogin_CallBack(originalRequest)
{
var objXml = originalRequest.responseXML;
//alert(originalRequest.responseTEXT);
try
{
if(objXml.getElementsByTagName("return")[0].firstChild.nodeValue == "true")
{
progressBar.isNeedConfirmButton = false;
progressBar.isNeedProgressBar = true;
progressBar.SetStatus("<img src='../images/error.gif' align='absmiddle'> Login successful, loading, please wait..");
//login success
location.href='admin_index.htm';
}
else
{
progressBar.isNeedConfirmButton = true;
progressBar.isNeedProgressBar = false;
progressBar.focusItem = "username";
progressBar.SetStatus("<img src='../images/error.gif' align='absmiddle'> Sorry, login failed!" + objXml.getElementsByTagName("msg")[0].firstChild.nodeValue);
$ ('btnOK').disabled = false;
}
}
catch(err)
{
progressBar.isNeedConfirmButton = true;
progressBar.isNeedProgressBar = false;
progressBar.focusItem = "username";
progressBar.SetStatus("<img src='../images/error.gif' align='absmiddle'> Sorry, login failed!" + err.message);
$('btnOK').disabled = false;
}
}
</script>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr>
<td colspan="3" height="30"></td>
</tr>
<tr>
<td width="21%">Username:</td>
<td colspan="2">
<input type="text" tabindex="1" id="username" name="username" chname="username" notempty="true" size="20" style="width:180px;" /></ td>
</tr>
<tr>
<td>Password:</td>
<td colspan="2"><input type="password" tabindex="2" id="password" name="password" chname="password" notempty="true" size="20" style="width: 180px;" /></td>
</tr>
<tr>
<td>Verification code:</td>
<td colspan="2">
<input type="text" style="width:120px;" id="rnd" tabindex="3" chname="Verification code" class="input_1" notempty="true" onKeyUp="value=value.replace( /[^d]/g,'')"/>
<img alt="Verification code" src="../rnd.do?type=admin_rnd" border="0" usemap="absmiddle"/></td>
</tr>
<tr>
<td class="white"> </td>
<td width="22%"><input type="submit" Class="input_1" id="btnOK" value="Login" tabindex="4"></td>
<td width="57%"><input type="reset" Class="input_1" value="Reset"></td>
</tr>
<tr>
<td colspan="3" height="2"></td>
</tr>
<tr>
<td colspan="3"></td>
</tr>
</table>
prototype.js download http://edzh.com/scripts/prototype.js