I'm trying to get the session storage to work with radio buttons in this scenario:
I have one radio button contain only one checkbox option. I named this element #input1
On the same page I have another radio button contain only one checkbox option. I named this element #input2
I connected both these elements to the same field in the database, which means checking one of the buttons, unchecks the other, which is what I want. My problem is that session storage doesn't seem to work with the current code I have:
import { session } from 'wix-storage';
$w.onReady(function () {
$w('#input1').value = session.getItem("city");
$w('#input2').value = session.getItem("citytwo");
});
export function input1_change(event) {
let city = $w('#input1').value
session.setItem("city", city);
}
export function input2_change(event) {
let citytwo = $w('#input2').value
session.setItem("citytwo", citytwo);
}
Thanks
Thanks Yisrael, In the console log it shows the name of the city chosen. (JAPAN, SINGAPORE) I should probably have used checkboxes like you said. Although I tried that now, but I get the same issue as with the radio buttons. The reason why I chose to only have one option in each group, was because I wanted to have an individual on change event for each option. As I'm new to coding, I couldn't figure out how to set that up.
So I made more groups with only one option, and made them all point to the same databasefield, so that only one answer would be submitted (selecting one button unchecks the other). But this is where the session storage problem begins, as soon as those buttons are connected to the same field in the database. Thank you for your patience..
I'm using radioGroups.
The value of my radiobuttons are text, and are connected to text fields in the database. The session storage works in scenarios where radioButtonGroup contains more options, but since I only have one option in each Radiogroup, the session storage doesnt work..
"I have one radio button contain only one checkbox option." Are you using a Radio Button group or a checkbox? It's not clear to me.
Note that session storage saves strings. If the value of your radio/checkbox is a number, or true/false, then it won't work. You will need to convert the value to a field.