Retreiving value from session and textfield is returning blank or [object object] error

I simply want to take the email address that a user inputs into a text field on the main home page, then use that value to become a placeholder in a new text field in a subsequent LightBox Form.

This should all happen with one click of the button: button6
But the value in the LightBoxForm always returns empty or with the phrase [Object object] as an error. It never shows the actual email address. What could be the problem here?

Any help is greatly appreciated!

HOME PAGE CODE
import {session} from ‘wix-storage’ ;

$w.onReady( function () {
});

export function button6(event, $w) {
session.setItem( ‘Email’ , $w( “#inputMain” ).value);
}

LIGHT BOX CODE
import {session} from ‘wix-storage’ ;

$w.onReady( function () {
fillEmail();
});

function fillEmail (){
let subE = session.getItem( ‘Email’ ); //Edit: getCurrentItem() is now getItem(). Code still doesn’t work
$w( “#inputLightBox” ).placeholder = subE;
}

Hello jab,

well we have here some problems with your CODE.

Please take a look how to retrieve the session.value back out of the wix-storage.

This is not correct!

let subE = session.getCurrentItem('Email');

Example from CORVID-API: —> the correct way.

import {session} from 'wix-storage';

let value = session.getItem("key"); // "value"

HOMEPAGE

import {session} from 'wix-storage';

$w.onReady(function () {   });

export function button6(event, $w) {
    session.setItem('Email', $w("#inputMain").value);
}

LIGHTBOX

import {session} from 'wix-storage';

$w.onReady(function () {
    fillEmail();
});

function fillEmail (){
 let subE = session.getItem('Email');
    $w("#inputLightBox").placeholder = subE;
}

Thank you. I made the correct change to getItem() and now I’m getting [object Object] that auto fills the field. Can you explain this?

Sorry i can’t explain this behaviour, because it works fine on my test-page.

EDIT: Try this one on your homepage…

import {session} from 'wix-storage';

$w.onReady(function () {   });

export function button6_click(event) {
    session.setItem('Email', $w("#inputMain").value);
}

I do not know how you navigate to the light-box (how you open your light-box)?

@russian-dima Thanks for trying! It still didn’t work unfortunately. Could any of the following be the issue?

  1. I’m using a Lightbox, instead of a page
  2. Could something be wrong with the “session” data storage?

@jab

This example works exactly with the given code.

https://russian-dima.wixsite.com/meinewebsite/lightbox

Homepage-code:

import {session} from 'wix-storage';
import wixWindow from 'wix-window';


$w.onReady(function () {   });

export function button66_click(event) {
    session.setItem('Email', $w("#inputMain").value);
    setTimeout(()=>{wixWindow.openLightbox("Lightbox1");},150)
}

Lightbox-Code:

import {session} from 'wix-storage';

$w.onReady(function () {
    fillEmail();
});

function fillEmail (){
 let subE = session.getItem('Email');
    $w("#input14").placeholder = subE;
}