How to store which checkbox is checked in quiz
I am creating a quiz for the company i work for, i am only an apprentice learning, but id like to know how to save which checkbox is ticked, but i dont know the first thing about this, as im learning.
It was made with VS 2010 And is written in ASP.
<script>
$(document).ready(function () {
var AnswersString = "<%#Eval("Answer") %>";
var NumberOfAnswers = AnswersString.split(',').length;
$(":checkbox").click( function()
{
if(CheckedTotal() > NumberOfAnswers)
$(this).removeAttr('checked');
});
function CheckedTotal()
{
return $(":checked").length;
}
});
</script>
<tr runat="server" >
<td colspan="2">
<asp:Label ID="Label3" runat="server" Text='<%#Eval("Question") %>' />
</td>
</tr>
<tr id="Tr1" runat="server" >
<td width="50%">
<asp:Label ID="Label1" runat="server" Text='<%#Eval("A1") %>' />
<br />
<br />
<asp:CheckBox ID="CheckBox2" CssClass="CheckBoxCheck"
runat="server" />
</td>
<td width="50%" >
<asp:Label ID="Label2" runat="server" Text='<%#Eval("A2") %>' />
<br />
<br />
<asp:CheckBox ID="CheckBox3" CssClass="CheckBoxCheck"
runat="server" />
</td>
</tr>
<tr id="Tr2" runat="server" >
<td>
<asp:Label ID="Label4" runat="server" Text='<%#Eval("A3") %>' />
<br />
<br />
<asp:CheckBox ID="CheckBox4" CssClass="CheckBoxCheck"
runat="server" Checked="False" />
</td>
<td >
<asp:Label ID="Label5" runat="server" Text='<%#Eval("A4") %>' />
<br />
<br />
<asp:CheckBox ID="CheckBox5" CssClass="CheckBoxCheck"
runat="server" />
</td>
</tr>
<tr id="Tr3" runat="server" >
<td>
<asp:Label ID="Label6" runat="server" Text='<%#Eval("A5") %>' />
<br />
<br />
<asp:CheckBox ID="CheckBox6" CssClass="CheckBoxCheck" runat="server" />
</td>
<td >
<asp:Label ID="Label7" runat="server" Text='<%#Eval("A6") %>' />
<br />
<br />
<asp:CheckBox ID="CheckBox7" CssClass="CheckBoxCheck" runat="server" />
</td>
</tr>
}
}
protected void testQuestions_OnItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
CheckBox chkSource1 = e.Item.FindControl("CheckBox1") as CheckBox;
CheckBox chkSource6 = e.Item.FindControl("CheckBox6") as CheckBox;
CheckBox chkSource7 = e.Item.开发者_如何学GoFindControl("CheckBox7") as CheckBox;
Label lblSource6 = e.Item.FindControl("Label6") as Label;
Label lblSource7 = e.Item.FindControl("Label7") as Label;
if (lblSource6.Text == string.Empty)
{
chkSource6.Visible = false;
}
if (lblSource7.Text == string.Empty)
{
chkSource7.Visible = false;
}
}
}
精彩评论