Displaying pages based on sessionid

Hi

I’m a complete JavaScipt newbie so I thought using Wix would give me the help I need.

I have a page where the user chooses an image


the user then submits their answer


and is taken back to the previous page, but I don’t want it to show the image they previously answered. As they aren’t logged in I thought I would use their SessionID but I don’t seem to be calling it correctly. I wanted to show images that they haven’t answered.


it’s supposed to show the SessionID where it says “value” just to show meI’m at least calling it correctly.

My code is:

import {session} from ‘wix-storage’ ;
// …
let value = session.getItem( “key” ); // “value”

$w.onReady( function () {
$w( ‘#message’ ).text = session.getItem( “key” );
});

Also is there a website I can go too to learn, as you can see I’m woeful :persevere:

Thanks

Tom

You have to set the “key” on page1 and get it on the the second page.
then you should use if(){} condition to decide what to show based on the retrieve key.

See:
https://www.wix.com/velo/reference/wix-storage/storage/setitem
https://www.wix.com/velo/reference/wix-storage/storage/getitem

  • for general learning:

Thank you for your reply JD, it’s very much appreciated. I’ve put the code
import {session} from ‘wix-storage’ ;
// …
session.setItem( “key” , “value” );

into the page where you guess, and the code

import {session} from ‘wix-storage’ ;
// …
let value = session.getItem( “key” ); // “value”

$w.onReady( function () {
$w( ‘#message’ ).text = session.getItem( “key” );
});

into the selection page, but it’s still returning “value”. Do I have to set “key”, “value” to something?


also you said I have to write an if () condition. Have you got an example? Those reference websites don’t tell a beginner anything, Or maybe it does but I’m well below a beginner.:disappointed_relieved:

Thanks

Tom

Yes,
See the red one?

session.setItem("key", value);

That should be the actual value you wish to store.

  1. For example (in case of sperate static images):
if(value === "something"){
    $w("#image1").collapse();
    $w("#image2").expand();
}

ah I see, I’ll give it a go. Thank you😀

Thank you J.D! I am making progress, thank you for dumbing down your answer so I could understand it :yum:.

I’ve run into another problem but I’m trying to fix it myself, rather than continuously posting on here…

Thanks

Tom