<!DOCTYPE html>
<
html
lang
=
"en"
>
<
head
>
<
meta
charset
=
"UTF-8"
>
<
meta
http-equiv
=
"X-UA-Compatible"
content
=
"IE=edge"
>
<
meta
name
=
"viewport"
content
=
"width=device-width, initial-scale=1.0"
>
</
head
>
<
body
>
<
div
style="display: flex;
flex-direction: column;
align-items: center;
justify-content: center;">
<
h2
>Welcome To GFG</
h2
>
<
input
type
=
"text"
id
=
"inputName"
placeholder
=
"Enter Your Name"
>
<
br
>
<
input
type
=
"text"
id
=
"inputCountry"
placeholder
=
"Your Country"
>
<
br
>
<
button
onClick
=
"addData()"
>
Add Data
</
button
>
<
p
id
=
"para"
></
p
>
</
div
>
<
script
>
function addData() {
if (typeof (Storage) !== "undefined") {
var name = document.getElementById(
"inputName").value;
var country = document.getElementById(
"inputCountry").value;
localStorage.setItem("Name", name);
localStorage.setItem("Country", country);
var para = document.getElementById(
"para").innerHTML = "Hey "
+ localStorage.getItem("Name") + "!" +
"<
br
>" + "Welcome To India, You are from "
+ localStorage.getItem("Country") + ".";
}
else {
var para = document.getElementById(
"para").innerHTML ="Error! You browser "
+ "doesn't support HTML storage object";
}
}
</
script
>
</
body
>
</
html
>