
I've just installed Google Chrome web browser. I can say it's a Google product indeed: simple, powerful and elegant.
new AjaxCSSJS('css/grid.css', 'css'); new AjaxCSSJS('js/ajaxform.js', 'js');
new AjaxCSSJS('js/ajaxform.js', 'js'); var af = new AjaxForm("frmProfile", "profile.act.php", "loader1.gif", "profileBoard");
new AjaxCSSJS('js/ajaxform.js', 'js', function() { var af = new AjaxForm("frmProfile", "profile.act.php", "loader1.gif", "profileBoard"); });
Method | Description |
submit() | You can submit the form by calling this function, but it is not necessary to use it usually, for example you can set the last field onBlure event to a function which calls this method. |
reset() | You can reset the form and clear the message board by calling this method, but it is not necessary usually and it is called from other methods of the class. |
resetForm() | You can reset the form but not clear the message board by calling this method. |
hideForm() | This method will hide the form element (form tag). You may call this function when the server script has processed the data and the process was successful and user won't need the form anymore, similar to the login forms after successful login. |
showMessage(msg, color) | This method let you show a message to the user such as data validation messages. The firs parameter is the message itself which is string and the second one is the color of message which is string too and could contain a color name e.g. "red" or a color value e.g. "#FF0000" |
focusForm() | By calling this method the first input of the form will receive the focus. You may call this method after creating the object in order to make form ready to receive user's data. |
<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript" src="ajaxform.js"></script>
<script type="text/javascript">
<!--
var ajaxForm = new AjaxForm("form1", "action1.php", "loader1.gif", "board");
ajaxForm.focusForm();
//-->
</script>
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$login = false;
if (empty($username)) {
$message = "You should enter your username!";
$color = "red";
} else if (empty($password)) {
$message = "You should enter your password!";
$color = "#FF7000";
} else if($username == 'ehsun' && $password == '7') {
$login = true;
$message = "You have logged in successfully.";
$color = "#335599";
} else {
$message = "Your username or password is incorrect!";
$color = "#9F9000";
}
echo "<script>";
echo "ajaxForm.showMessage('$message', '$color');";
if ($login) {
echo "ajaxForm.hideForm();";
} else {
echo "ajaxForm.focusForm();";
}
echo "</script>";
sleep(3);
?>