Reputation: 15866
aspx script:
<script type="text/javascript">
$(document).ready(function() {
$(".div_soru").hide();
$(".div_soru").first().show();
$(".onceki").click(function() {
if ($(this).closest(".div_soru").prev(".div_soru").html() != null) {
$(this).closest(".div_soru").hide();
$(this).closest(".div_soru").prev().show();
$(".bitir").hide();
$(".sonraki").show();
}
});
$(".sonraki").click(function() {
if ($(this).closest(".div_soru").next(".div_soru").html() != null) {
$(this).closest(".div_soru").hide();
$(this).closest(".div_soru").next().show();
if ($(this).closest(".div_soru").next().next().html() == null) {
$(".bitir").show();
$(".sonraki").hide();
}
}
});
});
</script>
and aspx:
<asp:Repeater ID="Repeater_sorular" runat="server" OnItemDataBound="Repeater_sorular_OnItemDataBound"
OnItemCommand="Repeater_sorular_ItemCommand">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<div class="div_soru">
<div class="div_soru_wrapper">
<div style="font-weight: bolder; padding: 5px;">
(<%#(((RepeaterItem)Container).ItemIndex+1).ToString() %>
/
<%# Eval("SoruSayisi")%>)
<%#Eval("Subject")%>
</div>
<asp:RadioButtonList ID="RadioButtonList_secenekler" runat="server" Visible='<%# Eval("TypeId").ToString() == "2" %>'
DataSource='<%#Eval("Secenekler")%>' DataTextField="OptionName" DataValueField="OptionId">
</asp:RadioButtonList>
<asp:CheckBoxList ID="CheckBoxList_secenekler" runat="server" Visible='<%# Eval("TypeId").ToString() == "1" %>'
DataSource='<%#Eval("Secenekler")%>' DataTextField="OptionName" DataValueField="OptionId">
</asp:CheckBoxList>
</div>
<div class="div_nav_buttons">
<table>
<tr>
<td id="onceki" class="onceki">
<img src="../Img/adminicons/geri.gif" />
</td>
<td id="sonraki" class="sonraki">
<img src="../Img/adminicons/ileri.gif" />
</td>
<td id="bitir" class="bitir">
<asp:ImageButton ID="ImageButton_kaydet" runat="server" CommandName="kaydet" ImageUrl="~/Img/adminicons/kaydet.gif"
CommandArgument='<%# Container.ItemIndex %>' OnClientClick="return confirm('Anketi kaydetmek istediğinize emin misiniz?');" />
</td>
</tr>
</table>
</div>
</div>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
This script hide radio groups. And I show them one by one with using next and prev button. I want to show an error message if a radio in one of radio gruop is not select. How can I current radio group selected value.
I try this but this is getting radio value from the first radio group.
var selectedRadios = $(".div_soru_wrapper input:radio:checked").val();
I think I cant explain clearly. I hope you understand what I want to do :) Thanks.
Upvotes: 0
Views: 1733
Reputation: 262979
If you want to check if there is a checked radio button in the currently visible group, the :visible selector can help you:
if ($(".div_soru_wrapper:visible input:radio:checked").length) {
// There is a checked radio button in the currently visible group.
} else {
// There is no checked radio button in the currently visible group.
}
Upvotes: 1