-4

I am creating a bunch of radio buttons for each row in HTML and I cannot figure out a way to store the user-selected radio button for each row using the localStorage method in Javascript and also cannot figure out how to retrieve and display it on the web page.

This is my code snippet for the radio buttons in HTML:

<input type="radio" id="r1" name="radio" value="1">
<input type="radio" id="r2" name="radio" value="2">

<br>

<input type="radio" id="r11" name="radio2" value="1">
<input type="radio" id="r22" name="radio2" value="2">

Please suggest to me a way and send a code snippet of how I can store the selected radio buttons in localStorage and retrieve it to a page. Please don't recommend me using a database as this project is due shortly.

  • consider describe what you have tried. maybe some javascript snippets you already have – lastr2d2 May 25 '21 at 06:17
  • Basiclly, you could use jQuery for the purpose. #Store: 1. Use jQuery for fetching value of DOM elements and storing them into a json object. 2. Store the json object into localStorage. #Retrieve: 1. Retrieve json object from localStorage. 2. Use the json object for restoring value of radio buttons by jQuery. – Epic Chen May 25 '21 at 06:50

1 Answers1

0

Js Fiddle Link

 $("input:radio[name='s']:checked").val());
  • This requires jQuery. – Andy May 25 '21 at 06:24
  • This is great, it works. However, can you please make it display in a web page and in a table and also store it permanently? So basically everytime the link is clicked, the next selected radio buttons start from below row. – Henil Patel May 25 '21 at 07:21