-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
102 lines (77 loc) · 3.54 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//when the entire DOM tree is loaded then all the functions will be ready to use
$(document).ready(function() {
// adds inactive class to all tabs except the first tab
$('#tabs li a:not(:first)').addClass('inactive');
//hides all the content containers then shows the first one
$('.container').hide();
$('.container:first').show();
// start of tab switching function
$("#tabs li a").click(function() {
var x = $(this).attr("id"); // stores the clicked tab id for concatnation later
if($(this).hasClass("inactive") ) { // if the clicked tab has the inactive class
$("#tabs li a").addClass("inactive"); // adds inactive class to all tabs
$(this).removeClass("inactive"); // removes inactive class on clicked tab
$(".container").hide(); // hides all container content
$("#" + x + "Page").show(); // concants the target id container to show up
}
});
$("img").hover(function() {
$(this).toggle("hide");
},
function () {
$(this).toggle("hide");
});
// CREDITS to stack overflow users "Barlas Apaydin" and "cgp" for original code
// link to stack overflow page
// https://stackoverflow.com/questions/11645081/how-to-build-simple-tabs-with-jquery
// $('#tabs li a').click(function(){
// var t = $(this).attr('id');
// if($(this).hasClass('inactive')){ //this is the start of our condition
// $('#tabs li a').addClass('inactive');
// $(this).removeClass('inactive');
// $('.container').hide();
// $('#'+ t + 'C').fadeIn('slow');
// }
// });
// document.getElementById("submit").addEventListener("click", function(event) {
// checkForm();
$("form").submit(function(event) {
// Prevent default form action. DO NOT REMOVE THIS LINE
event.preventDefault();
// $("#formErrors").html("hello there");
var formErrors = false;
var errorMessages = "";
errorMessages += "<ul>";
// --------------------------------------------------------------------------------
// checks for name ---------------------------------------
if ($("#fullname").val().length <= 1) {
// if name is more than one character
errorMessages += "<li>Missing full name.</li>";
$("#fullname").addClass("error");
formErrors = true;
}
else {
// if meets requirement than remove the error message
$("#fullname").removeClass("error");
}
// checks for email ------------------------------
var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
if (!emailPattern.test($("#email").val())) {
// if fails the test then display error message
errorMessages += "<li>Invalid or missing email address</li>";
$("#email").addClass("error");
formErrors = true;
} else {
$("#email").removeClass("error");
}
// -------------------------------------------------------------------------
errorMessages += "</ul>"
if (formErrors) {
$("#formErrors").html(errorMessages);
$("#formErrors").style.diplay = "block";
} else {
$("#formErrors").hide();
}
});
// end of form submit
}); // end of script