A
A
A
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>javascript form</title>
<style type="text/css">
{
box-sizing: border-box;
}
.input1 { background-color: #cfefe9; color:
#383636; padding: 12px 20px; border: none; border-
radius: 4px; cursor: pointer; float: left;
}
.input1:hover {
background-color: #e2f2e3;
}
.input1, select, textarea { width:
100%; padding: 12px;
border: 1px solid #ccc; border-radius: 4px; resize: vertical;
}
.row{
font-size: 150%;
}
.invalid{
font-weight: bold;
}
table{
border-radius: 20px;
background-color: #f4f1f1; padding: 20px;}
.button {
background-color: #555a55; border: none;
color: #f5f5f5; padding: 15px 32px; text-align:
center; text-decoration: none; display: inline-block;
font- size: 16px; margin: 4px 2px; cursor: pointer;
-webkit-transition-duration: 0.4s; transition-duration: 0.4s;
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19);
}
</style>
</style>
<script>
if (!/^\d{10}$/.test(form["mobile"].value)) {
alert("Invalid Mobile Number. It must be a 10 digit number."); valid = false;
}
if (!/\w+@\w+\.\w+/.test(form["email"].value)) { alert("Invalid email address."
);
valid = false;
}
if (valid) alert("valid"); return valid;
}
</script>
</head>
<body>
<header>
<h1>Online Product Entry</h1>
</header>
<form onsubmit="event.preventDefault();validation(this)" id="form">
<table >
<tr>
<td >
Product's ID: <br><input type="Text" placeholder="A-Z
0- 9" id="productId" class="input1" >
<br>
<span id="productIderror" class="invalid"></span>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<br>
<span id="quantityerror" class="invalid"></span>
</td>
</tr>
<tr>
<td >
</td>
</tr>
<tr>
<td>
id="totalValue" class="input1">
<br>
<span id="totalValueerror" class="invalid"></span>
</td>
</tr>
<tr>
<td>
Date of Purchase :<br><input size="80px" type="date"
</tr>
<tr>
</td>
<td>
<tr>
<td>
</tr>
<tr>
</td>
<td>
<br>
<input style=" height: 50px;" type="submit" name="submit"
</form>
<script language="JavaScript"> var d = new
Date(); function f(n) { return n < 10 ? '0' + n :
n; }
var random_num = Math.floor(Math.random() * (99999999999
- 10000000000)) + 10000000000;
random_num = d.getFullYear() + f(d.getMonth()+1) + f(d.getDate()) +
random_num; document.form.UMinvoice.value = random_num;
</script>
<fieldset>
<legend>Product Checkout</legend>
<button id="myBtn" class="button">checkout</button>
<p id="demo"></p>
<script>
document.getElementById("myBtn").addEventListener("click", function(){ document
.getElementById("demo").innerHTML = "Done";
});
</script>
</fieldset>
</table>
</form>
</body>
</html>
Screenshot:
AJAX
Create a Product Page with Tile of Images and add a JavaScript with XHR to add
description to all images when the user moves the mouse over the images and
add Target page for click event on the image about the description of the
product.
CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<!--Required meta tags-->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--jQuery-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.
js"></script>
<!--Bootstrap CSS-->
<link href="https://cdn.jsdelivr.net/npm/[email protected]
beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-
giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="
anonymous">
<!--Custom Stylesheet-->
<link rel="stylesheet" href="style.css">
<!--Favicon-->
<link rel="shortcut icon" href="/assets/favicon.ico" type="image/x-icon">
<body>
<div class="app-container">
<div class="app-left">
<div class="app-header">
<div class="app-filter-wrapper">
<button class="filter-dropdown-button">
<span>All Categories</span>
<svg xmlns="http://www.w3.org/2000/svg" fill="none"
stroke="curre ntColor" stroke-width="2" stroke-linecap="round" stroke-
linejoin="round" class="feather feather-chevron-down" viewBox="0 0 24 24">
<path d="M6 9l6 6 6-6" />
</svg>
</button>
<input class="filter-search-
input" type="text"
placeholder="Search...">
</div>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
fill="n one" stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke- linejoin="round" class="feather feather-shopping-bag">
<defs />
<path d="M6 2L3 6v14a2 2 0 002 2h14a2 2 0 002-2V6l-3-
4zM3 6h18M16 10a4 4 0 01-8 0" />
</svg>
</button>
</div>
<div class="app-left-content">
<div class="app-left-content-header">
<h1 class="content-title">Discover <span>the best</span></h1>
<a href="#" class="content-link">See More</a>
</div>
<div class="app-content-field">
<div class="product-box medium">
<img class="product-box-
image" src="https://images.unsplash.com/photo-1531471689044- dd3ca86632e1?
ixlib=rb- 1.2.1&ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw
%3D&auto=format&fit=crop& w=2250&q=80" alt="Product">
<div class="product-box-details">Decoration <span>55</span></div>
</div>
<div class="product-boxes">
<div class="product-box-wrapper three">
<div class="product-box medium">
<img class="product-box-
image" src="https://images.unsplash.com/photo-1510877073473-
6d4545e9c2af?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-
1.2.1&auto=format&fit=crop&w=1234&q=80" alt="Product">
<div class="product-box-details">Tables <span>55</span></div>
</div>
<div class="product-box medium">
<img class="product-box-
image" src="https://images.unsplash.com/photo-1519710164239- da123dc03ef4?
ixlib=rb- 1.2.1&ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw
%3D&auto=format&fit=crop& w=1234&q=80" alt="Product">
<div class="product-box-details">Lamps <span>45</span></div>
</div>
<div class="product-box medium">
<img class="product-box-
image" src="https://images.unsplash.com/photo-1526827826797-
7b05204a22ef?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-
1.2.1&auto=format&fit=crop&w=1234&q=80" alt="Product">
<div class="product-box-details">Shelves <span>25</span></div>
</div>
</div>
<div class="product-box-wrapper two">
<div class="product-box medium">
<img class="product-box-
image" src="https://images.unsplash.com/photo-1519961655809-
34fa156820ff?ixlib=rb-
1.2.1&ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&auto=format&fit=crop&
w=1234&q=80" alt="Product">
<div class="product-box-details">Sofa <span>55</span></div>
</div>
<div class="product-box medium">
<img class="product-box-
image" src="https://images.unsplash.com/photo-1556910585- 09baa3a3998e?
ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-
1.2.1&auto=format&fit=crop&w=1301&q=80" alt="Product">
<div class="product-box-details">Kitchen <span>105</span></div>
</div>
</div>
</div>
</div>
<div class="app-content-field second">
<div class="product-box-wrapper three">
<div class="product-box medium">
<img class="product-box-
image" src="https://images.unsplash.com/photo-1502920924215- 5646fe685bef?
ixlib=rb- 1.2.1&ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw
%3D&auto=format&fit=crop& w=2250&q=80" alt="Product">
<div class="product-box-details">Mirrors <span>35</span></div>
</div>
<div class="product-box medium">
<img class="product-box-
image" src="https://images.unsplash.com/photo-1453904300235-
0f2f60b15b5d?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-
1.2.1&auto=format&fit=crop&w=1233&q=80" alt="Product">
<div class="product-box-details">Plants <span>25</span></div>
</div>
<div class="product-box medium">
<img class="product-box-
image" src="https://images.unsplash.com/photo-1604014237256- 11d475e2a2d8?
ixlib=rb- 1.2.1&ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw
%3D&auto=format&fit=crop& w=1234&q=80" alt="Product">
<div class="product-box-details">Bathroom <span>25</span></div>
</div>
</div>
</div>
</div>
</div>
<div class="app-right">
<button class="app-right-hide">
<svg xmlns="http://www.w3.org/2000/svg" fill="none"
stroke="currentCo lor" stroke-width="2" stroke-linecap="round" stroke-
linejoin="round" class="feather feather-x" viewBox="0 0 24 24">
<path d="M18 6L6 18M6 6l12 12"/>
</svg>
</button>
<div class="app-right-content">
<ul class="product-list">
<li class="product-list-item fadeIn">
<div class="product-img-wrapper">
<img class="product-
image" src="https://images.unsplash.com/photo-1544030288- e6e6108867f6?
ixid=MXwxMjA3fDB8MHxzZWFyY2h8MTJ8fGZ1cm5pdHVyZXxlbnwwfDF8MHw%3D&ix lib=rb-
1.2.1&auto=format&fit=crop&w=900&q=60" />
</div>
<div class="product-list-itemContent">
<div class="product-info">
<h2 class="product-info-
header"> Monokai
</h2>
<p class="product-info-subheader">
125.00 $ <span class="product-color">Yellow</span>
</p>
</div>
<div class="product-amount-wrapper">
<button class="product-amount-button increase">
<svg xmlns="http://www.w3.org/2000/svg" fill="none"
stroke= "currentColor" stroke-width="2" stroke-linecap="round" stroke-
linejoin="round" class="feather feather-chevron-up" viewBox="0 0 24
24">
<path d="M18 15l-6-6-6 6" />
</svg>
</button>
<span class="product-amount">2</span>
<button class="product-amount-button decrease">
<svg xmlns="http://www.w3.org/2000/svg" fill="none"
stroke= "currentColor" stroke-width="2" stroke-linecap="round" stroke-
linejoin="round" class="feather feather-chevron-down" viewBox="0 0 24 24">
<path d="M6 9l6 6 6-6" />
</svg>
</button>
</div>
</div>
</li>
<li class="product-list-item fadeIn">
<div class="product-img-wrapper">
<img class="product-
image" src="https://images.unsplash.com/photo-1541533260371-
b8fc9b596d84?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-
1.2.1&auto=format&fit=crop&w=1234&q=80" alt="product"/>
</div>
<div class="product-list-itemContent">
<div class="product-info">
<h2 class="product-info-
header"> Night Owl
</h2>
<p class="product-info-subheader">
225.00 $ <span class="product-color">Gray</span>
</p>
</div>
<div class="product-amount-wrapper">
<button class="product-amount-button increase">
<svg xmlns="http://www.w3.org/2000/svg" fill="none"
stroke= "currentColor" stroke-width="2" stroke-linecap="round" stroke-
linejoin="round" class="feather feather-chevron-up" viewBox="0 0 24
24">
<path d="M18 15l-6-6-6 6" />
</svg>
</button>
<span class="product-amount">1</span>
<button class="product-amount-button decrease">
<svg xmlns="http://www.w3.org/2000/svg" fill="none"
stroke= "currentColor" stroke-width="2" stroke-linecap="round" stroke-
linejoin="round" class="feather feather-chevron-down" viewBox="0 0 24 24">
<path d="M6 9l6 6 6-6" />
</svg>
</button>
</div>
</div>
</li>
<li class="product-list-item fadeIn">
<div class="product-img-wrapper">
<img class="product-
image" src="https://images.unsplash.com/photo-1506377295352- e3154d43ea9e?
ixlib=rb- 1.2.1&ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw
%3D&auto=format&fit=crop& w=1234&q=80" />
</div>
<div class="product-list-itemContent">
<div class="product-info">
<h2 class="product-info-
header"> Material
</h2>
<p class="product-info-subheader">
105.00 $ <span class="product-color">Gray</span>
</p>
</div>
<div class="product-amount-wrapper">
<button class="product-amount-button increase">
<svg xmlns="http://www.w3.org/2000/svg" fill="none"
stroke= "currentColor" stroke-width="2" stroke-linecap="round" stroke-
linejoin="round" class="feather feather-chevron-up" viewBox="0 0 24
24">
<path d="M18 15l-6-6-6 6" />
</svg>
</button>
<span class="product-amount">1</span>
<button class="product-amount-button decrease">
<svg xmlns="http://www.w3.org/2000/svg" fill="none"
stroke= "currentColor" stroke-width="2" stroke-linecap="round" stroke-
linejoin="round" class="feather feather-chevron-down" viewBox="0 0 24 24">
<path d="M6 9l6 6 6-6" />
</svg>
</button>
</div>
</div>
</li>
</ul>
<div class="product-details fadeIn">
<div class="product-details-line">
<span class="product-details-text">Sub Total</span>
<span class="product-details-text amount">455.00 $</span>
</div>
<div class="product-details-line">
<span class="product-details-text">Shipment</span>
<a href="#" class="product-details-link">Check details</a>
<span class="product-details-text amount">15.00 $</span>
</div>
<div class="product-details-line">
<span class="product-details-text">Discount</span>
<a href="#" class="product-details-link">Remove</a>
<span class="product-details-text amount">-10.00 $</span>
</div>
<div class="product-details-summary">
<span class="product-details-text">Total</span>
<span class="product-details-text amount">460.00 $</span>
</div>
</div>
</div>
<button class="checkout-button">Checkout Payment</button>
</div>
</div>
</body>
</head>
</html>
Sho.js
$("#card-container").ready(async function() {
var cards = await getAllProducts();
const product = {
"name": name,
"imageURL":
url, "price":
price,
"description": description
};
if (result) {
alert("Product has been added!");
window.location.href =
"index.html";
} else {
alert("Failed to add product, sorry");
}
});
$("#productNameInput").val(product.name);
$("#productImageURLInput").val(product.imageURL);
$("#productPriceInput").val(product.price);
$("#productDescriptionInput").val(product.description);
});
const id = window.location.href.split("?
id=").pop(); const name = $
("#productNameInput").val();
const url = $
("#productImageURLInput").val(); const price
= $("#productPriceInput").val();
const description = $("#productDescriptionInput").val();
const product = {
"name": name,
"imageURL":
url,
"price": price, "description": description
};
var result = await updateProduct(id, product); if (result) {
alert("Product has been update!");
window.location.href = "index.html";
} else {
alert("Failed to update product, sorry");
}
});