<HTML>
<HEAD>
<TITLE>Verifying Form Input</TITLE>
<SCRIPT>
<!-- Activate Cloaking Device
//****************************************************************
//
// Form Validation with JavaScript
//
// Developed by Timothy Wallace, timothy@essex1.com
//
//****************************************************************
// Used for View Source
function WinOpen(){
alert('\nPage will load to full screen.\n\nUse View/Document Source from menu bar to view source.\n\nClose new window to return to this page. ');
window.open("jv_vld3.html","DisplayWindow","menubar=yes");
window.open("jv_vld3.html","DisplayWindow","menubar=yes");
// double call for Macs
}
// Information messages
function Info(){
alert("\nThis is just an example of how to validate forms. No actual submission takes place. Instead, the info is dynamically written to a page.");
alert("\nNAME : accepts only a-z, A-Z, & spaces\nE-MAIL : @ & . are required\nBROWSER : will detect changes\nCOUNTRY : accepts only a-z, A-Z, & spaces\nNUMBER : accepts only digits 0-9\nPHONE NUMBER : accepts only digits 0-9 & requires ten digits");
}
// Clears fields and puts focus on Name form
function Reset(){
document.forms[0].elements[0].value = "";
// name
document.forms[0].elements[1].value = "";
// email
document.forms[0].elements[2].value = navigator.appName + " " + navigator.appVersion;
// browser
document.forms[0].elements[3].value = "";
// country
document.forms[0].elements[4].value = "";
// decimal #
document.forms[0].elements[5].value = "";
// area code
document.forms[0].elements[6].value = "";
// phone prefix
document.forms[0].elements[7].value = "";
// phone number
document.forms[0].elements[8].value = "";
// comment
document.forms[0].elements[0].focus();
}
// Reports if all forms have filled out properly.
function testForms(){
if ( (isName() ) && (isEmail()) && (isBrowser()) && (isCountry()) && (isNum()) && (isPhoneNumber()) && (isComment()) ){
alert("\nAll forms appear to be filled out properly.\n\nYour submission will now be made.");
var name = document.forms[0].elements[0].value;
var email = document.forms[0].elements[1].value;
var browser = document.forms[0].elements[2].value;
var country = document.forms[0].elements[3].value;
var number = document.forms[0].elements[4].value;
var area = document.forms[0].elements[5].value;
var prefix = document.forms[0].elements[6].value;
var phone = document.forms[0].elements[7].value;
var comment = document.forms[0].elements[8].value;
document.open();
document.write("<HTML><HEAD><TITLE>"+"Confirmation Page"+"</TITLE></HEAD>");
document.write("<BODY BGCOLOR=FFFFFF LINK=FF0000 VLINK=FF0000 ALINK=FF0000>");
document.write("<CENTER><H1><FONT COLOR=800000>"+"Your Submission has been received."+"</FONT></H1>");
document.write("<TABLE>");
document.write("<TR><TD align=left><FONT COLOR=0000FF><B>"+"NAME : "+"</B></FONT>"+name+"</TR>");
document.write("<TR><TD align=left><FONT COLOR=0000FF><B>"+"EMAIL : "+"</B></FONT>"+email+"</TR>");
document.write("<TR><TD align=left><FONT COLOR=0000FF><B>"+"BROWSER : "+"</B></FONT>"+browser+"</TR>");
document.write("<TR><TD align=left><FONT COLOR=0000FF><B>"+"COUNTRY : "+"</B></FONT>"+country+"</TR>");
document.write("<TR><TD align=left><FONT COLOR=0000FF><B>"+"NUMBER : "+"</B></FONT>"+number+"</TR>");
document.write("<TR><TD align=left><FONT COLOR=0000FF><B>"+"PHONE NUMBER : "+"</B></FONT>"+area+" - "+prefix+" - "+phone+"</TR>");
document.write("<TR><TD align=left><FONT COLOR=0000FF><B>"+"COMMENT : "+"</B></FONT>"+comment+"</TR>");
document.write("</TABLE><BR>");
document.write("</CENTER></BODY></HTML>");
document.close();
}
}
// Checks the NAME field.
function isName(){
var str = document.forms[0].elements[0].value;
// Return false if name field is blank.
if (str == ""){
alert("\nThe NAME field is blank.\n\nPlease enter your name.")
document.forms[0].elements[0].focus();
return false;
}
// Return false if characters are not a-z, A-Z, or a space.
for (var i = 0; i < str.length; i++){
var ch = str.substring(i, i + 1);
if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != ' '){
alert("\nThe NAME field only accepts letters & spaces.\n\nPlease re-enter your name.");
document.forms[0].elements[0].select();
document.forms[0].elements[0].focus();
return false;
}
}
return true;
}
// Checks the E-MAIL field.
function isEmail(){
// Return false if e-mail field is blank.
if (document.forms[0].elements[1].value == ""){
alert("\nThe E-MAIL field is blank.\n\nPlease enter your e-mail address.")
document.forms[0].elements[1].focus();
return false;
}
// Return false if e-mail field does not contain a '@' and '.' .
if (document.forms[0].elements[1].value.indexOf ('@',0) == -1 || document.forms[0].elements[1].value.indexOf ('.',0) == -1){
alert("\nThe E-MAIL field requires a \"@\" and a \".\"be used.\n\nPlease re-enter your e-mail address.")
document.forms[0].elements[1].select();
document.forms[0].elements[1].focus();
return false;
}
else {
return true;
}
}
// Checks the BROWSER field.
function isBrowser(){
// Allows for a change to detected browser upon confirmation.
if (document.forms[0].elements[2].value != navigator.appName + " " + navigator.appVersion){
if (confirm("\nYou've changed your browser type.\n\nClick on OK to keep changes.\n\nClick on Cancel to restore detected browser."))
return true
else {
document.forms[0].elements[2].value = navigator.appName + " " + navigator.appVersion;
return true;
}
}
else
return true;
}
// Checks the COUNTRY field.
function isCountry(){
var str = document.forms[0].elements[3].value;
// Return false if country field is blank.
if (str == ""){
alert("\nThe COUNTRY field is blank.\n\nPlease enter your country.")
document.forms[0].elements[3].focus();
return false;
}
// Return false if characters are not a-z, A-Z, or a space.
for (var i = 0; i < str.length; i++){
var ch = str.substring(i, i + 1);
if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != ' '){
alert("\nThe COUNTRY field only accepts letters & spaces.\n\nPlease re-enter your country.");
document.forms[0].elements[3].select();
document.forms[0].elements[3].focus();
return false;
}
}
return true;
}
// Checks the NUMBER field.
function isNum(){
var str = document.forms[0].elements[4].value;
// Return false if number field is blank.
if (str == ""){
alert("\nThe NUMBER field is blank.\n\nPlease enter a number.");
document.forms[0
Javascript tutorial
需积分: 10 31 浏览量
2008-09-04
12:38:25
上传
评论
收藏 96KB ZIP 举报
brazil3r
- 粉丝: 0
- 资源: 28
最新资源
- 数据流图数据流图数据流图数据流图数据流图.txt
- 西北工业大学软件工程或计算机专业程序设计III基础大作业第一题万年历
- k-means聚类算法k-means聚类算法k-means聚类算法k-means聚类算法.txt
- 简单的EA程序,均线趋势交易
- 电脑工具集(非常好用)
- python爬虫-10-where条件语句-范围查询.ev4.rar
- python爬虫-09-where条件语句-逻辑运算符.ev4.rar
- ubuntu安装nvidia显卡驱动ubuntu安装nvidia显卡驱动ubuntuubuntu安装nvidia显卡驱动.txt
- python爬虫-08-where条件语句-比较运算符.ev4.rar
- android超炫的图片浏览器.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈