-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyscript.js
131 lines (107 loc) · 3.2 KB
/
myscript.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
"Demo Shopping Cart" is a non comprehensive e-commerce website developed for academic purposes only. This is just a demonstration of a simple shopping cart and it may contain bugs and errors.
Design and development by Rasan Samarasinghe. (c) 2015 All Rights Reserved.
*/
function validateLogin(){
if(document.getElementById("txtEmail").value == ""){
alert("Enter email address");
document.getElementById("txtEmail").focus();
return false;
}
if(document.getElementById("txtPassword").value == ""){
alert("Enter password");
document.getElementById("txtPassword").focus();
return false;
}
return true;
}
function validateRegister(){
if(document.getElementById("txtName").value == ""){
alert("Enter name");
document.getElementById("txtName").focus();
return false;
}
if(document.getElementById("txtAddress").value == ""){
alert("Enter address");
document.getElementById("txtAddress").focus();
return false;
}
if(document.getElementById("txtEmail").value == ""){
alert("Enter email address");
document.getElementById("txtEmail").focus();
return false;
}
var email = document.getElementById("txtEmail").value;
var atpos = email.indexOf("@");
var dotpos = email.lastIndexOf(".");
var len = email.length;
if(atpos < 2 || dotpos-atpos < 3 || len-dotpos < 3){
alert("Enter a valid email address");
document.getElementById("txtEmail").focus();
return false;
}
if(document.getElementById("txtPassword").value == ""){
alert("Enter password");
document.getElementById("txtPassword").focus();
return false;
}
if(document.getElementById("txtConfPassword").value != document.getElementById("txtPassword").value){
alert("Confirm password do not match");
document.getElementById("txtPassword").focus();
return false;
}
return true;
}
function validateAddProduct(){
if(document.getElementById("txtName").value == ""){
alert("Enter name");
document.getElementById("txtName").focus();
return false;
}
if(document.getElementById("txtDescription").value == ""){
alert("Enter description");
document.getElementById("txtDescription").focus();
return false;
}
if(document.getElementById("fileImage").value == ""){
alert("Select an image");
return false;
}
if(document.getElementById("txtPrice").value == ""){
alert("Enter price");
document.getElementById("txtPrice").focus();
return false;
}
if(isNaN(document.getElementById("txtPrice").value)){
alert("Enter a valid price");
document.getElementById("txtPrice").focus();
return false;
}
return true;
}
function validateOrder(){
if(document.getElementById("txtCredit").value == ""){
alert("Enter credit card number");
document.getElementById("txtCredit").focus();
return false;
}
if(isNaN(document.getElementById("txtCredit").value) || document.getElementById("txtCredit").value.length != 10){
alert("Enter a 10 digit credit card number");
document.getElementById("txtCredit").focus();
return false;
}
if(document.getElementById("txtAddress").value == ""){
alert("Enter shipping address");
document.getElementById("txtAddress").focus();
return false;
}
return true;
}
function confirmDelete(){
var ret = confirm("Are you sure you want to delete this?");
return ret;
}
function confirmValidate(){
var ret = confirm("Are you sure you want to validate this?");
return ret;
}