Expand my Community achievements bar.

Adobe Campaign User Groups are live now. Join our Adobe Campaign User Groups and connect with your local leaders!
SOLVED

To get values from previous page

Avatar

Level 1

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?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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');

     Manoj
     Find me on LinkedIn

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

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');

     Manoj
     Find me on LinkedIn