To get values from previous page | Community
Skip to main content
February 5, 2024
Solved

To get values from previous page

  • February 5, 2024
  • 1 reply
  • 562 views

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Manoj_Kumar

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

1 reply

Manoj_Kumar
Community Advisor
Manoj_KumarCommunity AdvisorAccepted solution
Community Advisor
February 5, 2024

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  | https://themartech.pro