|
|
|
|
|
|
| |
It describes the type of form validations for textboxes, emails, select type using javascript and using only one alert nmessage to view all validations
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Form Validations</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!--code-->
<script>
function Required(element, description, type)
{
this.element = element;
this.description = description;
this.type = type;
}
function textOK(e) { return (e.value != "") ? true : false; }
function selectOK(e) { return (e.options[e.selectedIndex].text != "-Select-") ? true : false; }
function emailOK(e)
{
var at = e.value.indexOf('@');
var dot = e.value.lastIndexOf('.');
var space = e.value.indexOf(' ');
var len = e.value.length - 1;
return ((at > 1) && (dot >= at + 1) && (dot < len) && (space == -1)) ? true : false;
}
function isReady(f)
{
//alert("in");
var r = new Object();
r[0] = new Required(f.gender, "Gender", "select");
r[1] = new Required(f.fname, "First Name", "text");
r[2] = new Required(f.lname, "Last Name", "text");
r[3] = new Required(f.email, "Email Address", "email");
var msg = "";
for (var i in r)
{
if ((r[i].type == "text" && !textOK(r[i].element)) ||
(r[i].type == "email" && !emailOK(r[i].element))||
(r[i].type == "select" && !selectOK(r[i].element)))
{
msg += "- " + r[i].description + "\n";
}
}
var msg1 = "";
var mChecked = false;
if (mChecked == false) {
msg = msg + msg1;
}
if (msg.length > 0)
{
msg = "Either You omitted the following required field(s) \n Or Information You Provided is Incorrect :\n\n" + msg;
msg += "\nPlease complete the form and submit it again."
alert(msg);
return false;
}
return true;
}
//--></script>
<!--/code-->
</head>
<body>
<table width="100%">
<form name="frm" onSubmit="return isReady(this);" method="post">
<tr><td valign="top">Gender: <select name="gender"><option value="-Select-">-Select-</option><option value="m">Male</option><option value="f">Female</option></select></td></tr>
<tr><td valign="top">FirstName: <input type="text" name="fname"></td></tr>
<tr><td valign="top">LastName: <input type="text" name="lname"></td></tr>
<tr><td valign="top">Email: <input type="text" name="email"></td></tr>
<tr><td valign="top"><input type="submit" name="btnsubmit" value="Submit"></td></tr>
</form>
</table>
</body>
</html> | | |
|
| Sed, a coder's best friend. This lovely linux command allows you to swap strings in a file. Great for changing a variable name in a script with
multiple files. Categories : HTML and PHP, HTML and PHP | | | This PHP function creates dropdown select lists for time and date that you can change, outputs a 14 char MySQL timestamp in a text field Categories : PHP, MySQL, Java Script, HTML and PHP | | | showing Help (assistance) to the user while filling html forms. Categories : HTML, Java Script, Form Processing | | | PHP4 session helper HTML file.
Categories : PHP, Java Script, HTML and PHP, Sessions | | | PHP and javascript mouseover, mouseout, and mousedown events Categories : PHP, Java Script, Form Processing, Beginner Guides | | | Local-to-user date and time display regardless of time zone or where the website's server is located Categories : PHP, Date Time, HTML and PHP, Java Script | | | Pull Down Surfing - Surf on Change Categories : Java Script, MySQL, HTML and PHP, PHP, Databases | | | Javascript URL and Email Validation Categories : Java Script, Data Validation, Form Processing, Email, URLs | | | Sql Builder Categories : PHP, HTML and PHP, Databases, General SQL, Form Processing | | | Hilight Form Element onFocus Categories : Java Script, Form Processing, CSS | | | Simple POST and GET example Categories : PHP, Beginner Guides, Form Processing, HTML and PHP | | | Dynamic form field Categories : PHP, HTML and PHP, Form Processing | | | Form Processing : with alert Highlight field name which is not filled by user Categories : Java Script, Form Processing, Data Validation, Beginner Guides, Web Design | | | Newbie Notes #9 - Hyperlinking a post Categories : PHP, Java Script, HTML and PHP, Beginner Guides | | | Adding a Filter to a Text Element Categories : Java Script, Data Validation, Form Processing | |
| | | | El Sayed Othman wrote :1728
I'll use it from now ON .. thanQ :)
| |
|
|
|