Question: Include comments -When the calculate tuition and fees button is clicked it should ask if the student would like to apply to the university -If
Include comments
-When the calculate tuition and fees button is clicked it should ask if the student would like to apply to the university -If they hit OK a validation function should run that calls the functions to validate the form. If the form validates a alert displays saying the information has been submitted and that someone from the university will contact them via email. Use the template attached as the action attribute in the form tag. -If the cancel button is clicked a alert appears that says no information has been submitted to the university -Validate that first & last name has been entered -Validate that an email address has been entered that isn't numeric -Validate that a tuition type has been chosen -Validate that the number of credits is numeric and has been entered -Validate that a major has been selected -If an item fails validation an alert will appear explaining the issue and the form contents will remain available for modification and then to resubmit
HOME.HTML
VALIDATE.JS
function validateForm() { var form = document.forms["userform"];//acccess form with the name var fname = form["fname"].value;//acccess firstname value using by name=fname parameter var lname = form["lname"].value;//acccess lastname value using by name=lname parameter var email = form["emailid"].value;//acccess email value using by name=emailid parameter var tuition_type = form["tuition_type"].value;//acccess tuition_type value using by name=tuition_type parameter var credits = form["credits"].value;//acccess credits value using by name=credits parameter var major = form["major"].value;//acccess major value using by name=major parameter var emailpatt = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,4})$/;//regular expression for global email address var validationReport="";// all error are append to this string intially we don't have no errors so it is empty if (fname == null || fname == undefined || fname == "") { validationReport+="[*]FirstName is Required*"+" ";//if firstname is not entered } else { } if (lname == null || lname == undefined || lname.length
validationReport+="[*]LastName is Required*"+" ";//if lastname is not entered
} else {
} if (email == null || email == undefined || email.length
} else if (!emailpatt.test(email)) { validationReport+="[*]Invalid Email"+" ";//if invalid email is not entered
} else { } if (tuition_type == null || tuition_type == undefined || tuition_type.length
} else { }
if (credits == null || credits == undefined || credits == "") { validationReport+="[*]credits Field is Required*"+" ";//if credits are not entered } else if (isNaN(credits)) { validationReport+="[*]Credits should be numerical"+" ";//if Non numerical credits are not entered
} else { }
if (major == null || major == undefined || major == "") { validationReport+="[*]Major is required*"+" ";//if Major is not selected } else { var major1=getMajor(); if(major1==""){ validationReport+="[*]Invalid Major is selected"+" ";//if Major is not selected form the listed above
}else{ } }
if(validationReport==""){ //if validation errors var a=confirm("Are you sure to Submit?"); if(a==true){ //user confrim to submit return true; }else{ //user press cancel to submit return false; } }else{ //If validation Errors are there we presenting them with a alert alert("Validations is Failed: "+validationReport); return false; } }
function getTutitonType() {
if (document.getElementById("instate1").checked) {
return "In-State";
} else if (document.getElementById("outofstate1").checked) {
return "Out-of-State";
} else if (document.getElementById("international1").checked) {
return "International Tuition "
}
return "";
}
// Full time or part time
function getFullTimeOrPartTime() {
var fulltime1 = document.getElementById("fulltime1").checked;
var parttime1 = document.getElementById("parttime1").checked;
if (fulltime1) {
return "Full Time";
} else if (parttime1) {
return "Part Time";
}
return "";
}
// Majors
function getMajor() {
major = String(document.getElementById("major").value);
if (major == "CIS") {
return "Computer & Information Systems";
}
else if (major == "Business") {
return "Business";
}
else if (major == "Economics") {
return "Economics";
}
else if (major == "Finance") {
return "Finance";
}
else if (major == "General") {
return "General Education";
}
else if (major == "maj6") {
return "Data Science";
}
else if (major == "maj7") {
return "Artificial Intelligence";
}
else if (major == "maj8") {
return "Mechanical Engineering";
}
else if (major == "maj9") {
return "Embedded System";
}
else if (major == "maj10") {
return "Electrical Engineering";
}
return "";
}
//Displays Alert when an option is selected
function displayAlert() {
major = String(document.getElementById("major").value);
if (major == "CIS") {
alert('Computer & Information Systems majors are great for people who enjoy computers, coding, networking, and databases.');
}
else if (major == "Business") {
alert('Business Management degrees can get you a wide range of jobs and require you to have a lot of knowledge in finance, economics, or accounting.');
}
else if (major == "Economics") {
alert('An economics degree can et you positoins in a wide range of positions related to finance and technology.');
}
else if (major == "Finance") {
alert('The finance degree involves helping businesses and consumers organize money.');
}
else if (major == "General") {
alert('This choice will let you take a few classes to better gauge what you would like your degree to be in.');
}
else if (major == "maj6") {
alert('A Data Science degree helps you to gain expertisse in big data.');
}
else if (major == "maj7") {
alert('An Artificial Intelligence Degree helps to understand machine intelligence');
}
else if (major == "maj8") {
alert('Mechanical Engineering helps you understand basic mechanism and principles behind various machines');
}
else if (major == "maj9") {
alert('Embedded System degree will help one to design embedded smart systems.');
}
else if (major == "maj10") {
alert('An Electrical Engineering degree will help you to deal with various electrical components and circuits.');
}
else {
alert('Please Select a valid Major');
}
}
// This gets the information for displaying a summary of everything on the form as an alert
function buildStudentProfile() {
var name = document.getElementById('sname').value;
var emailid = document.getElementById('emailid').value;
var credits = document.getElementById("credits").value;
var str = "Student Name: " + name + ' ';
str += "Email ID: " + emailid + ' ';
str += "Tuition Type: " + getTutitonType() + ' ';
str += "Fulltime or part time: " + getFullTimeOrPartTime() + ' ';
str += "Number of credits: " + credits + ' ';
str += "Major: " + getMajor() + ' ';
return str;
}
//This function hides the amount on pressing reset button
function hideResult() {
document.getElementById("result").style.visibility = "hidden";
}
function result() {
var fulltime1 = document.getElementById("fulltime1").checked;
var parttime1 = document.getElementById("parttime1").checked;
var confirmation = confirm("Are you sure want to print results?");
var credits = document.getElementById("credits").value;
var instft = [3746, 232, 33.20]
var instpt = [312, 20, 33.20]
var instate1 = document.getElementById("instate1").checked;
var oosft = [5619, 353, 49.80]
var oospt = [468, 30, 49.80]
var outofstate1 = document.getElementById("outofstate1").checked;
var ift = [7305, 353, 63.90];
var ipt = [609, 30, 63.90];
var international1 = document.getElementById("international1").checked;
var name = document.getElementById('sname').value;
// This line will print the results if the confirmation is true
if (confirmation === true) {
var results;
var secondConfirmation;
// In state full time
if (instate1 == true && fulltime1 == true && credits >= 12 && credits
results = (instft[2] * credits) + (instft[0] + instft[1]);
secondConfirmation = confirm(buildStudentProfile() + ((instft[2] * credits) + (instft[0] + instft[1])));
}
// In state part time
else if (instate1 == true && parttime1 == true && credits
results = (credits * instpt[0]) + (credits * instpt[1]) + (credits * instpt[2]);
secondConfirmation = confirm(buildStudentProfile() + ((credits * instpt[0]) + (credits * instpt[1]) + (credits * instpt[2])));
}
// Out of state full time
else if (outofstate1 == true && fulltime1 == true && credits >= 12 && credits
results = (oosft[2] * credits) + (oosft[0] + oosft[1]);
secondConfirmation = confirm(buildStudentProfile() + ((oosft[2] * credits) + (oosft[0] + oosft[1])));
}
// Out of state part time
else if (outofstate1 == true && parttime1 == true && credits
results = (credits * oospt[0]) + (credits * oospt[1]) + (credits * oospt[2]);
secondConfirmation = confirm(buildStudentProfile() + ((credits * oospt[0]) + (credits * oospt[1]) + (credits * oospt[2])));
}
// International full time
else if (international1 == true && fulltime1 == true && credits >= 12 && credits
results = (ift[2] * credits) + (ift[0] + ift[1]);
secondConfirmation = confirm(buildStudentProfile() + ((ift[2] * credits) + (ift[0] + ift[1])));
}
// International part time
else if (international1 == true && parttime1 == true && credits
results = (credits * ipt[0]) + (credits * ipt[1]) + (credits * ipt[2]);
majorirmation = confirm(buildStudentProfile() + (credits * ipt[0]) + (credits * ipt[1]) + (credits * ipt[2])); } else if (secondConfirmation === false) {
alert('Correct any errors on the form.');
secondConfirmation = true;
}
else {
alert('Correct any errors on the form.');
}
var name = document.getElementById("sname").value;
document.getElementById("result").innerHTML = name + " would owe $" + results + "";
}
else {
alert('Correct any errors on the form.');
}
}
FORMPROCESS.HTML
formData = formData.substring(1, formData.length);
while (formData.indexOf("+") != -1) {
formData = formData.replace("+", " ");
}
formData = unescape(formData);
var formArray = formData.split("&");
for (var i=0; i
document.writeln(formArray[i] + "
");
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
