Saving and retrieving radio button selection on a separate webpage using JavaScript

One interesting feature of my website is a radio button field that appears on multiple pages. Although the radio buttons are the same on each page, the content below them varies. These radio buttons come with default values, but I have implemented a way to save the selected value so that even after refreshing or navigating to another page, the chosen option remains checked.

It's important to note that every page has a similar radio button section with different context underneath. My goal is to ensure continuity; if "choice 1" is selected on page 1, then it should automatically be selected on pages 2 and 3 as well. I've utilized local storage to store and retrieve the radio button value. However, I'm still figuring out how to fetch this stored value and display the corresponding checked button upon refresh or page switch.

#vuejs 2.6 vuetify 2.3

<template>
…
<v-radio-group v-model=radio row>
    <v-radio label=“choice 1” value=“radio1”></radio>
    <v-radio label=“choice 2” value=“default”></radio>
</v-radio-group>
<h1>Content page 1</h1>

…
</template>

<script>
export default {
    components: {},
    data() {
    …
    radio: “default”,
    …
    },
    methods: {
       saveRadio(value) {
          localStorage.setItem("radio",value);
          console.log(localStorage.getItem("radio"));
       }
    },
   watch: {
      radio(value) {
         this.saveRadio(value);
      }
   }   
}
</script>

Answer №1

const settings = {
    components: {},
    storage: localStorage.getItem("settings") || "default",
}
export default settings;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips on updating checkbox background color after being selected

I've been working on creating checkboxes for seat selection in Angular using a TypeScript file, but I'm facing an issue where the background color of the checkbox doesn't change after checking them. Here's my TypeScript function: gener ...

Creating a unique button for STRIPE payments in Laravel 5.1

I have a Stripe payment button in my ecommerce website that looks like this: <script src="https://checkout.stripe.com/checkout.js" class="stripe-button" data-key="pk_test_yNuawoy0jUqj1GC14jwcQR5d" data-amount="{{ $total * 100}}" data-name="dixard" data ...

Issue with VueRouter not scrolling to anchor tags was encountered

I am currently tackling an issue with my Vue.js/Laravel8 project on a single page application. I am struggling to make the VueRouter scroll to a specific section on the page. The page is divided into various sections that are accessible by scrolling down, ...

Sending data from express js to a different server

Currently, I am faced with a scenario where I need to send a file from Jquery to my Express server and then transfer that request to another server without parsing the file in the Express server. Below are the code snippets I have been using so far: Jquery ...

Steps for sending a value to an AngularJS $http success function

I have a question that is very much like the one posed here: How to pass a value to an AngularJS $http success callback As per Angular.js The $http legacy promise methods success and error have been deprecated. You should use the standard then method ...

Trouble displaying data in Vue Laravel retrieved from method

I've been staring at this code for two days and I feel like I'm missing something obvious. The goal here is to display an array of data in a modal, but for some reason it's not populating correctly when using v-for. If you can spot where I w ...

Convert JavaScript code to Google Appscript

Looking for guidance on incorporating Javascript code into my Google Appscript. Here is the code snippet: I have a separate Stylesheet.html file saved. Can someone advise me on how to invoke the functions within the html file? <script> //google. ...

The width of the plotbands on the yAxis of a stacked bar graph is adjusting as the series are dynamically toggled,

https://ibb.co/h7tmwtr https://ibb.co/syRTyPG For the first time, I have included 5 plot bands which looked great. However, when I added a series and toggled it on a stacked bar graph, the plot bands' width started increasing. I want to maintain the ...

Spring MVC applications might experience slow loading times when loading RequireJS libraries

Recently, I integrated RequireJS into my Spring MVC application to manage dependencies for various libraries, including jQuery and jQuery UI. Although I have successfully implemented it, I am facing an issue whenever the page is loaded or refreshed. Initia ...

Pushing information from an embedded array using Typescript

I am encountering an issue when trying to extract data from a nested array. The JSON object I have looks like this: { component: Assembly, title: "Assembly", path: "/assembly", sections: { title: "Frame Assembly", steps: { ["Step ...

Step-by-step guide to implementing onClick functionality within a component

Currently, I am utilizing https://github.com/winhtaikaung/react-tiny-link to showcase posts from various blogs. While I am able to successfully retrieve the previews, I am facing an issue with capturing views count using onClick(). Unfortunately, it appear ...

Troubleshooting custom buttons error when using carousel in Nuxt app: "Flickity is not defined"

I am attempting to connect my own personalized buttons to a flickity carousel within a nuxt application. Within my carousel component, the following code is present: <template> <ClientOnly> <Flickity ref="flickit ...

Is it necessary for me to include images in the DOM in order to combine them utilizing the canvas element?

I'm interested in combining two images using canvas. However, I'm curious if it's necessary to have these images in the DOM. What if I have multiple images with URLs but prefer not to preload them? ...

Creating a function that allows for the dynamic addition of rows in Angular with

I am currently working on implementing search and filter functionality, which requires adding rows dynamically. With hundreds of fields to filter, my boss has decided to organize them in dropdown menus (such as Manager, City, and Name in this example). The ...

Enhancing visuals with THREE.js and the power of transparency through EffectComposer

I am attempting to blend texture passes in a way that preserves the alpha channel. I have experimented with several methods to achieve this. The renderer has the alpha property set to true. Renderer with various setClearColor settings. The material on th ...

Is there a way to capture the stdout and stderr output from a WebAssembly module that has been generated using Emscripten in JavaScript?

In my C++ code snippet below: #include <iostream> int main() { std::cout << "Hello World!" << std::endl; return 0; } I compile the code using: emcc -s ENVIRONMENT=shell -s WASM=1 -s MODULARIZE=1 main.cpp -o main.js This c ...

Stop unwanted scrolling upwards by using jQuery ajax function $.load

I'm currently in the process of creating an ajax chat using jquery and php. Everything seems to be running smoothly except for one issue related to scrolling. Essentially, I've implemented a time-out function that automatically reloads the inner ...

Discover the Magic of CSS Animation

I am not experienced in CSS animations and have limited knowledge about animations. I am trying to create an animation where a grey box slides down from the top line above the login/register section, but currently it only fades in. If anyone can provide an ...

Develop a worldwide computed attribute within a plugin on Vue 3

I'm attempting to establish a universal computed property within a Vue 3 plugin in order for my property to be utilized reactively across any component. I am adhering to the standard Vue 3 pattern: app.config.globalProperties.$foo = ... This method a ...

Valid method of confirming a user's login status

Using AJAX requests, I have implemented a user area on my website. The "Log off" button is supposed to be displayed only when the user is logged in. Here is the AJAX request for logging in a user: function requestSI() { var xhr = getXMLHttpRequest(); xhr ...