-
Notifications
You must be signed in to change notification settings - Fork 0
/
bookDetailsWebsiteBySurajRay.js
47 lines (30 loc) · 1.26 KB
/
bookDetailsWebsiteBySurajRay.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
//Accessing the book name element
let bookNameEl = document.querySelector("h3");
//storing the img element
let bookImgEl = document.querySelector("#book-details div");
//Accessing the review element
let bookReviewEl = document.querySelector(".reviews");
//Accessing the book Rate element
let bookRateEl = document.querySelector(".rate");
//Deciphering data from previous page's redirection
//Function to get query parameters by name
function QueryParam(dataName) {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(dataName);
}
var bookImg = QueryParam("data1");
var bookName = QueryParam("data2");
var bookRate = QueryParam("data3");
var bookReview = QueryParam("data4");
//Assigning new data
bookImgEl.innerHTML = bookImg;
bookNameEl.innerText = bookName;
bookRateEl.innerText = bookRate;
bookReviewEl.innerText = bookReview;
//Adding alert messages to buy now and add to cart buttons
document.querySelector(".buy-now").addEventListener("click",()=>{
alert("Order placed\nYour order details will be emailed to your email address.\nThanks! - Suraj");
});
document.querySelector(".add-to-cart").addEventListener("click",()=>{
alert("Item added to cart\nThanks! - Suraj");
});