Overview For this assignment you will create a complex submit form that uses sev
ID: 3796760 • Letter: O
Question
Overview
For this assignment you will create a complex submit form that uses several javascript features.
Development and Requirements
Almost every web application has a submit form. For this assignment, you may choose any domain such as information inquiry, user registration, and online purchase, provided that your choice suggests enough details to meet the assignment requirements.
While the choice of domain and the details of the form are up to you, the resulting form should meet the following requirements:
The form must check at least one field for presence or valid format. If invalid, javascript should prevent the form from being submitted and provide a meaningful message to the user.
The form must provide at least one optional field that only appears if it is appropriate for a previous selection. For example, a text area might appear only if the user first checks a box labeled "My order has special requests".
At least one pop-up note that elaborates on one of the form labels.
To test your form, have it submit to http://facsrv.cs.depaul.edu/~cmiller/php/respond.php. This simple php page responds with a page summarizing all of the form parameters and their values.
Explanation / Answer
function formValidation(){
var uid = document.registration.userid;
var password =document.registration.password;
var uname = document.registration.username;
var uadd=document.registration.address;
var ucountry=document.registration.country;
var uzip=document.registration.address.zip;
var uemail=document.registration.address.email;
var umale=document.registration.address.male;
var ufemale=document.registration.address.female;
if(userid_validation(uid,5,12))
{
if(password_validation(password,7,12))
{
if(allLetter(uname))
{
if(alphanumeric(uadd))
{
if(countryselect(ucountry))
{
if(allnumeric(uzip))
{
if(validateEmail(uemail))
{
if(validgender(umale,ufemale))
{
}
}
}
}
}
}
}
}
}
return false;
}
function userid_validation(uid,mx,my)
{
var uid_len=uid.value.length;
if(uid_len==0 ||uid_len>=my || uid_len<mx)
{
alert("user id should not empty/length between "+mx+"to"+my+);
uid.focus();
return false;
}
return true;
}
function password_validation(password,mx,my)
{
var password_len=password.value.length;
if(password_len == 0||password_len>=my||password_len<mx)
{
alert("password should not be empty/length between "+mx+"+my);
password.focus();
return false;
}
return true;
}
function allLetter(uname)
{
var letters=/^[A-Za-z]+$/;
if(uname.value.match(letters))
{
return true;
}
else
{
alert("username must have alphabet characters only");
uname.focus();
return false;
}
}
function alphanumeric(uadd)
{
var letters=/^[0-9a-zA-Z]+$/;
if(uadd.value.match(letters))
{
return true;
}
else
{
alert('user address must have alphanumeric characters only');
uadd.focus();
return false;
}
}
function countryselect(ucountry)
{
if(ucountry.value == "Default")
{
alert('Select your country from the list');
ucountry.focus();
return false;
}
else
{
return true;
}
}
function allnumeric(uzip)
{
var numbers = /^[0-9]+$/;
if(uzip.value.match(numbers))
{
return true;
}
else
{
alert('ZIP code must have numeric characters only');
uzip.focus();
return false;
}
}
function ValidateEmail(uemail)
{
var mailformat = /^w+([.-]?w+)*@w+([.-]?w+)*(.w{2,3})+$/;
if(uemail.value.match(mailformat))
{
return true;
}
else
{
alert("You have entered an invalid email address!");
uemail.focus();
return false;
}
} function validgender(umale,ufemale)
{
x=0;
if(umale.checked)
{
x++;
} if(ufemale.checked)
{
x++;
}
if(x==0)
{
alert('Select Male/Female');
umale.focus();
return false;
}
else
{
alert('Form Succesfully Submitted');
window.location.reload()
return true;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.