Setting the value of a radio button with JQuery (ASP.NET MVC)
Posted
by Mario
on Stack Overflow
See other posts from Stack Overflow
or by Mario
Published on 2010-03-25T14:10:54Z
Indexed on
2010/03/25
14:13 UTC
Read the original article
Hit count: 395
asp.net-mvc
|jQuery
I have 2 "lists" of (4) radio buttons {value = "0", "1", "2", "3"} in all lists. The first list needs to drive the second list (which may occur multiple times). So if an option is selected in the first list, the SAME option is selected in the second list. It sounds weird, but it has a purpose. The first list is more of a "select all" type of list, and the second list is an individual selection list(s).
I have the value of the "selectall" list via JQuery:
$("#selectalllist").change(function() {
var str = $('input[name=selectall]:checked').val();
$(".radiolist").attr('checked', str); //This is my thinking
});
The current selected value is stored in the str variable, and that is seemingly correct (I used alert to tell me what is stored, and it comes up what I expect). I just need to set the value of the next set of lists. The second line of the code I thought would set the checked value of $(".radiolist") to the stored value, but it ALWAYS set the value to the last entry (value = "3").
I'm wondering if I have the wrong attribute in the .attr('', str) call? Any thoughts?
© Stack Overflow or respective owner