Saving dropbox and checkbox entries to local storage

I’m creating a form for website users to use where they have to fill out checkboxes and dropboxes. When they navigate to another page and then back to the form, their selections are cleared. Is there any way of storing this information locally to stop this from happening? I’ve had a look at the Wix help pages and haven’t been able to get code (like below) working… Thanks for the help in advance :slight_smile:

import { local } from ‘wix-storage’ ;

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

export function dropdown1_change ( event ) {
local . setItem ( “key” , $w ( ‘#dropdown1’ ). value );
}

$w . onReady ( function () {
$w ( ‘#dropdown1’ ). value = local . getItem ( “key” );
});

Your code is fine. Just move the getItem method to the first $w.onReady and delete the second $w.onReady.

  • use if:
$w.onReady(() => [
  const storedVal = local.getItem("key");
  if(storedVal){
    $w('#dropdown1').value = storedVal;
  }
})

Thanks, if I follow I now have:

import { local } from ‘wix-storage’ ;

$w . onReady (() => {
const storedVal = local . getItem ( “key” );
if ( storedVal ){
$w ( ‘#dropdown1’ ). value = storedVal ;
}
});

export function dropdown1_change ( event ) {
local . setItem ( “key” , $w ( ‘#dropdown1’ ). value );
}

Unfortunately still not working… any ideas?
Thanks for your help!

Make sure the dropdown1_change function is marked on the dropdown property panel.
Make sure you’re not using incognito/private browser.

thanks! got it working by changing ‘show initial text’ in dropdown settings to ‘item in dropdown’