Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
alizad
/
lab-10
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
950a88c1
authored
May 05, 2020
by
alizad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit
parents
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
162 additions
and
0 deletions
desktop.ini
index.html
script.js
desktop.ini
0 → 100644
View file @
950a88c1
[.ShellClassInfo]
InfoTip
=
This folder is shared online.
IconFile
=
C:
\P
rogram Files
\G
oogle
\D
rive
\g
oogledrivesync.exe
IconIndex
=
16
\ No newline at end of file
index.html
0 → 100644
View file @
950a88c1
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<title>
lab-10
</title>
</head>
<body>
<h1
id=
"caption"
>
AL's Shopping List
</h1>
<span>
Product Name:
</span>
<input
type=
"text"
id=
"item"
value=
""
>
<span>
Product Count:
</span>
<input
type=
"number"
id=
"count"
min=
1
value=
1
>
<button
type=
"button"
id=
"addToList"
>
Add
</button>
<table
id=
"tbl"
>
<tr>
<th>
Number
</th>
<th>
Product
</th>
<th>
Quantity
</th>
</tr>
</table>
<script
src=
"./script.js"
></script>
</body>
</html>
\ No newline at end of file
script.js
0 → 100644
View file @
950a88c1
function
addToList
()
{
var
product
=
productTF
.
value
;
var
quantity
=
quantityTF
.
value
;
if
(
product
.
length
>
0
)
{
addItemToList
(
data
[
"num"
],
product
,
quantity
);
let
tempItem
=
{};
tempItem
[
"num"
]
=
data
[
"num"
].
toString
;
tempItem
[
"item"
]
=
product
;
tempItem
[
"count"
]
=
quantity
;
data
[
data
[
"num"
].
toString
()]
=
tempItem
;
localStorage
.
setItem
(
usernameme
,
JSON
.
stringify
(
data
));
data
[
"num"
]
++
;
productTF
.
value
=
""
;
quantityTF
.
value
=
1
;
}
}
function
getCookie
(
cname
)
{
var
name
=
cname
+
"="
;
var
decodedCookie
=
decodeURIComponent
(
document
.
cookie
);
var
ca
=
decodedCookie
.
split
(
';'
);
for
(
var
i
=
0
;
i
<
ca
.
length
;
i
++
)
{
var
c
=
ca
[
i
];
while
(
c
.
charAt
(
0
)
==
' '
)
c
=
c
.
substring
(
1
);
if
(
c
.
indexOf
(
name
)
==
0
)
return
c
.
substring
(
name
.
length
,
c
.
length
);
}
return
""
;
}
function
removeItem
(
itemID
)
{
if
(
!
confirm
(
"Are you sure?"
))
return
;
var
item
=
document
.
getElementById
(
itemID
);
item
.
parentNode
.
removeChild
(
item
);
data
[
itemID
.
toString
()]
=
null
;
localStorage
.
setItem
(
usernameme
,
JSON
.
stringify
(
data
));
}
function
addToList
(
n
,
p
,
q
)
{
var
tr
=
document
.
createElement
(
"tr"
);
var
noF
=
document
.
createElement
(
"td"
);
var
productF
=
document
.
createElement
(
"td"
);
var
quantityF
=
document
.
createElement
(
"td"
);
tr
.
id
=
n
;
noF
.
innerHTML
=
n
+
"."
;
productF
.
innerHTML
=
p
;
quantityF
.
innerHTML
=
q
;
tr
.
appendChild
(
noF
);
tr
.
appendChild
(
productF
);
tr
.
appendChild
(
quantityF
);
table
.
appendChild
(
tr
);
tr
.
addEventListener
(
"click"
,
()
=>
{
removeItem
(
tr
.
id
);});
}
var
productTF
=
document
.
getElementById
(
"item"
);
var
quantityTF
=
document
.
getElementById
(
"count"
);
var
table
=
document
.
getElementById
(
"tbl"
);
var
username
=
getCookie
(
"username"
);
var
data
=
{
"num"
:
1
};
if
(
typeof
(
Storage
)
===
"undefined"
)
{
document
.
getElementById
(
"caption"
).
innerHTML
=
"ERROR"
;
}
else
{
if
(
usernameme
===
null
||
usernameme
===
""
||
usernameme
===
"null"
)
{
usernameme
=
sessionStorage
.
getItem
(
"username"
);
}
if
(
usernameme
===
null
||
usernameme
===
""
||
usernameme
===
"null"
)
{
usernameme
=
prompt
(
"Name"
);
setCookie
(
"username"
,
usernameme
,
60
);
sessionStorage
.
setItem
(
"username"
,
usernameme
);
localStorage
.
setItem
(
usernameme
,
JSON
.
parse
(
data
));
}
else
if
(
localStorage
.
getItem
(
usernameme
)
!==
null
)
{
data
=
JSON
.
parse
(
localStorage
.
getItem
(
usernameme
));
for
(
const
[
key
,
val
]
of
Object
.
entries
(
data
))
{
if
(
val
!==
null
&&
key
!==
"num"
)
addToList
(
key
,
val
[
"item"
],
val
[
"count"
]);
}
}
document
.
getElementById
(
"caption"
).
innerHTML
=
usernameme
+
"'s Shopping List"
;
document
.
getElementById
(
"addToList"
).
addEventListener
(
"click"
,
addToList
);
}
function
setCookie
(
cname
,
cvalue
,
exdays
)
{
var
d
=
new
Date
();
d
.
setTime
(
d
.
getTime
()
+
(
exdays
*
24
*
60
*
60
*
1000
));
var
expires
=
"expires="
+
d
.
toUTCString
();
document
.
cookie
=
cname
+
"="
+
cvalue
+
";"
+
expires
+
";path=/"
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment