Hi Team ,
I have made a webpage that displays a list of food items. When a user clicks the "Add to cart" button, the product should be recorded (I have made an array and stored the data in it). The user should then receive the product price and name values on the next page of the cart. Can someone assist me in resolving this problem?
Solved! Go to Solution.
Views
Replies
Total Likes
Hello @sarjoon
You can save this data from the array to a context variable in Webapp.
Server Side Code
Here are the steps you can follow:
1. Create a variable in web application properties let's say cartdata
2. Use this code to update this variable value when a customer clicks on add to cart
<script>
function addToCart(){
..
..
document.controller.setValue("/ctx/vars/cartData",myCartData); //myCartData is the array of items
..
..
}
</script>
Then you can use this context variable on the next page to get the results back.
<%= ctx.vars.cartData %>
Client Side
You can use local storage to save this data
localStorage.setItem('cartData',myCartData);
get value from localstorage
localStorage.getItem('cartData');
Views
Replies
Total Likes
Hello @sarjoon
You can save this data from the array to a context variable in Webapp.
Server Side Code
Here are the steps you can follow:
1. Create a variable in web application properties let's say cartdata
2. Use this code to update this variable value when a customer clicks on add to cart
<script>
function addToCart(){
..
..
document.controller.setValue("/ctx/vars/cartData",myCartData); //myCartData is the array of items
..
..
}
</script>
Then you can use this context variable on the next page to get the results back.
<%= ctx.vars.cartData %>
Client Side
You can use local storage to save this data
localStorage.setItem('cartData',myCartData);
get value from localstorage
localStorage.getItem('cartData');
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies