Shyam Dixit Shyam Dixit - 2 years ago 68
Javascript Question

Storing value of radio button in Local Storage

I think this is very silly question but i didn't get it.Actually I am trying to get values of checked radio button and store all to local Storage but it is showing null.

My HTML code is:

<div id="radioMediators" style="display:none; float:left; margin-left:50px;margin-top:8px;">
<input type="radio" name="M1P1" value="1">1
<input type="radio" name="M1P1" value="2">2
<input type="radio" name="M1P1" value="3">3
<input type="radio" name="M1P1" value="4">4
<input type="radio" name="M1P1" value="5">5
<input type="radio" name="M1P2" value="1">1
<input type="radio" name="M1P2" value="2">2
<input type="radio" name="M1P2" value="3">3
<input type="radio" name="M1P2" value="4">4
<input type="radio" name="M1P2" value="5">5
<input type="radio" name="M1P3" value="1">1
<input type="radio" name="M1P3" value="2">2
<input type="radio" name="M1P3" value="3">3
<input type="radio" name="M1P3" value="4">4
<input type="radio" name="M1P3" value="5">5
<input type="radio" name="M1P4" value="1">1
<input type="radio" name="M1P4" value="2">2
<input type="radio" name="M1P4" value="3">3
<input type="radio" name="M1P4" value="4">4
<input type="radio" name="M1P4" value="5">5
<input type="radio" name="M1P5" value="1">1
<input type="radio" name="M1P5" value="2">2
<input type="radio" name="M1P5" value="3">3
<input type="radio" name="M1P5" value="4">4
<input type="radio" name="M1P5" value="5">5

And for storing purpose I am using this code:

var a1=localStorage.getItem($('input[name="M1P1"]:checked'));

Same for all(M1P2,M1P2,M1P3,M1P4,M1P5)


But this is showing null.
What I did wrong.Please let me know.


Answer Source

I got it and found that it was a very silly question.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download