JQuery and radio buttons
Posted
by ognjenb
on Stack Overflow
See other posts from Stack Overflow
or by ognjenb
Published on 2010-05-26T09:37:40Z
Indexed on
2010/05/26
9:41 UTC
Read the original article
Hit count: 226
c#
|asp.net-mvc
<form id="Numbers1"
<table id="numbers">
<tr>
<th>
prvi_br
</th>
<th>
drugi_br
</th>
<th>
treci_br
</th>
</tr>
<% int rb = 1; %>
<% foreach (var item in Model) { %>
<tr>
<td>
<%= Html.Encode(item.prvi_br) %>
<input type="radio" name="<%= Html.Encode(rb) %>" value="<%= Html.Encode(rb) %>" id='<%= Html.Encode(item.prvi_br) %>'/>
</td>
<td>
<%= Html.Encode(item.drugi_br) %>
<input type="radio" name="<%= Html.Encode(rb) %>" value="<%= Html.Encode(rb) %>" id='<%= Html.Encode(item.drugi_br) %>'/>
</td>
<td>
<%= Html.Encode(item.treci_br) %>
<input type="radio" name="<%= Html.Encode(rb) %>" value="<%= Html.Encode(rb) %>" id='<%= Html.Encode(item.treci_br) %>'/>
</td>
<% rb=rb+1; %>
</tr>
<% } %>
</table>
<p>
<input type="submit" value="Save" />
</p>
</form>
With this script I get some info of selected radio:
<script type="text/javascript">
$(document).ready(function() {
var thevalue1;
var thevalue2;
$("#Numbers1").submit(function() {
$("input:radio:checked").each(function() {
thevalue1 = $("input:radio:checked").attr('id');
thevalue2 = $("input:radio:checked").val();
alert(thevalue1 + thevalue2);
});
});
});
</script>
If I have more rows this alert every time prints the information of first selected radio, why???
© Stack Overflow or respective owner