-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
90 lines (84 loc) · 3.24 KB
/
main.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
var pictureIndex = 1;
window.onload = function loadPictures() {
pictureIndex = 3;
var path = document.getElementsByClassName('listing')[0].id
var carousel = document.getElementById("pictureCarousel");
for (var i = 1; i <= 3; ++i) {
var newDiv = document.createElement("div");
newDiv.className = "picture-showcase";
var newImg = document.createElement("img");
newImg.src = path + "-" + i + ".jpg";
newDiv.appendChild(newImg);
pictureCarousel.appendChild(newDiv);
}
showPicture(pictureIndex);
}
function showPicture(direction) {
pictureIndex += direction;
var pictures = document.getElementsByClassName("picture-showcase");
if (pictureIndex > pictures.length) {
pictureIndex = 1
}
if (pictureIndex < 1) {
pictureIndex = pictures.length
}
for (i = 0; i < pictures.length; ++i) {
if (i != [pictureIndex - 1]) {
pictures[i].style.display = "none";
}
else {
pictures[pictureIndex - 1].style.display = "block";
}
}
}
function checkForm() {
document.getElementById("error").innerHTML = "";
var products = document.getElementById("products").value;
var quantity = document.getElementById("quantity").value;
var fname = document.getElementById("fname").value;
var lname = document.getElementById("lname").value;
var phoneNumber = document.getElementById("phoneNumber").value;
var street = document.getElementById("street").value;
var city = document.getElementById("city").value;
var state = document.getElementById("state").value;
var postalCode = document.getElementById("postalCode").value;
var shippingMethod = document.getElementById("shippingMethod").value;
var ccnumber = document.getElementById("ccnumber").value;
var ccv = document.getElementById("ccv").value;
var errors = [];
for (e of document.getElementById("myForm")) {
if (e.value == "" && e.id != "submit") {
errors.push(" " + e.id + " cannot be empty");
}
}
if (errors.length > 0) {
document.getElementById("error").innerHTML = errors;
return false;
}
if (isNaN(phoneNumber) || !(phoneNumber.length == 10 || phoneNumber.length == 11)) {
errors.push(" Invalid Phone Number");
}
if (isNaN(ccnumber) || ccnumber.length != 16) {
errors.push(" Invalid Credit Card Number");
}
if (isNaN(ccv) || !(ccv.length == 3 || ccv.length == 4)) {
errors.push(" Invalid CCV");
}
if (isNaN(postalCode) || postalCode.length != 5) {
errors.push(" Invalid Postal Code.")
}
if (errors.length > 0) {
document.getElementById("error").innerHTML = errors;
return true;
}
// window = window.open("mailto:[email protected]?subject=Purchase Form for: " + products
// + "&body=" + "Quantity = " + quantity
// + "%0AFirst Name = " + fname
// + "%0ALast Name = " + lname
// + "%0APhone Number = " + phoneNumber
// + "%0AShipping Address = " + street + " " + city + " " + state + ", " + postalCode
// + "%0AShipping Method = " + shippingMethod
// + "%0ACredit Card Number = " + ccnumber
// + "%0ACCV = " + ccv,
// 'emailWindow');
}