DOM 3 Swimming Pool Form Complete with diseparing error message
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>
<!-- <button class="button" id="btn" onclick="create()">Click to create heading</button>
<div id="demo"></div> -->
<div class="d-none" id="alert"></div>
<div class="container">
<div class="icon">🏊♂️</div>
<h1 class="heading">Under 18 Swimming Champaionship</h1>
<p class="desc">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corrupti, praesentium.</p>
<div class="flex">
<input type="text" id="name" placeholder="Enter The Name">
<input type="text" id="age" placeholder="Enter The Age">
</div>
<button class="button" onclick="register()">Click To Register</button>
</div>
<div id="usercontainer" class="user-container"></div>
<script src="app.js"></script>
</body>
</html>
//JS File
// let demo=document.getElementById("demo");
// demo.innerHTML="<h2>This is java</h2>"
// function create(){
// let heading = document.createElement("h1");
// heading.innerText="This is ne heading created";
// heading.classList.add("title");
// demo=document.getElementById("demo");
// demo.appendChild(heading);
// }
let users =[];
let userContainer=document.getElementById('usercontainer');
function render(){
userContainer.innerHTML=" ";
for(let i=0;i<users.length;i++){
let div = document.createElement('div');
let name = document.createElement('div');
let age = document.createElement('div');
name.innerText=users[i].name;
age.innerText=users[i].age;
div.classList="user";
// userContainer.appendChild(name);
// userContainer.appendChild(age);
userContainer.appendChild(div);
div.appendChild(name);
div.appendChild(age);
}
}
let alertt=document.getElementById('alert');
function showAlert(){
alertt.classList.remove('d-none');
alertt.classList.add("alert");
setTimeout(()=>{
alertt.classList.add('d-none');
// alertt.classList.add("alert");
}, 3000)
}
function register(){
let nameinp=document.getElementById('name');
let ageinp=document.getElementById('age');
let user = {
name : nameinp.value,
age : Number(ageinp.value)
}
if(user.age>=16 && user.age<=18){
users.push(user);
showAlert();
alertt.innerText="Registration Successful"
render();
}
else{
alertt.innerText="Registration unuccessful"
showAlert();
}
}
// CSS File
/* .title{
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
font-size: 32px;
margin: 20px auto;
border: 1px solid black;
width: 400px;
padding : 10px;
text-decoration: underline blueviolet;
border-radius: 5px;
} */
body{
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
.alert{
position: absolute;
top: 0;
right: 0;
margin-top: 10px;
background-color: rgb(255, 255, 204);
padding: 16px 32px;
color: rgb(137, 71, 0);
border-radius: 10px;
transition: 0.4;
}
.d-none{
display: none;
}
.container{
width: 550px;
margin: 100px auto;
border: 1px solid black;
border-radius: 10px;
padding: 10px;
text-align: center;
}
.icon{
font-size: 50px;
}
.flex{
display: flex;
gap: 10px;
}
input{
padding: 16px 32px;
width: 100%;
/* box-sizing: border-box; */
border: 1px solid black;
border-radius: 10px;
margin-bottom: 10px;
}
input:focus{
outline: none;
border-color: blueviolet;
}
.button{
padding: 16px 32px;
width: 100%;
border: none;
border-radius: 10px;
cursor: pointer;
font-size: 16px;
}
.user-container{
width: 550px;
margin: auto;
}
.user{
display: flex;
background-color: rgba(255, 255, 173, 0.937);
border-radius: 5px;
padding: 16px 32px;
gap: 50px;
margin-bottom: 10px;
}
Comments
Post a Comment