After research and lot of attempts of various implementations looking how to get radio button value from my application. Basically it is very simple radio button in file Index.cshtml :
<div class="col-md-2">
<div style="padding: 0 20px;">
<label for="star-filter2"> Projects vendors status:</label>
<fieldset id="star-filter2">
<input class="radioCheck2" id="rated-filter2" value="true" type="radio" name="starfilter2" />Rated<img src="~/images/check.png" alt="tick box" height="20" width="20" />
<br />
<input class="radioCheck2" id="rated-filter2" value="false" type="radio" name="starfilter2" />Not rated<img src="~/images/excl_mark.png" alt="excl mark" height="20" width="20" />
<br />
<input class="radioCheck2" id="rated-filter2" value="null" type="radio" name="starfilter2" />NULL<img src="~/images/excl_mark.png" alt="excl mark" height="20" width="20" />
</fieldset>
</div>
</div>
Here is my javascript code where I am trying to get selected radio button value:
$("#filter2").click(function () {
var showRated = $('#rated-filter2').is(':checked');
localStorage.setItem("showRated", showRated);
var location = $("#filter-button2").find("a").attr("href")....;
window.location.href = location;
});
In this code line: var showRated = $('#rated-filter2').is(':checked');
is working , but it is only to get value when it is checked. What I want , I want to get value of selected radio button, for example : true , "null" and any value which I insert into radio button.
I tried these lines, where I was getting 'undefined' or always false value.
$('#input[name=\'starfilter2\']:checked').val();
$('#rated-filter2:selected').val();
$('#input[name=starfilter2]:checked').val();
None of them it is not working.