Getting checked input values in a specific div - simple jquery question
Here is my div that is contained more than once by my page:
<div class="formContainerDiv" style="width:165px">
<table>
<tr>
<td colspan="2">
Assign To<br />
<asp:CheckBoxList ID="CheckBoxListLoginUsers" runat="server">
</asp:CheckBoxList>
<br />
Note<br />
<asp:TextBox ID="TextBoxNote" runat="server" TextMode="MultiLine" Width="150" ClientIDMode="Static" class="textBoxNote"></asp:TextBox>
<br />
</td>
</tr>
<tr>
<td>
<input type="button" class="saveAssignment" value="Save"/>
</td>
<td style="text-align: center;">
<a href="javascript:void(0)" class="formContainerDivClose">Close</a>
</td>
</tr>
</ta开发者_如何学Cble>
</div>
And that's my jquery function:
$(".saveAssignment").click(function () {
var div = $(this).parents(".formContainerDiv");
......
});
I can select the appropriate formContainerDiv. But I need to get the values of checked checkboxes and the value of TextBoxNote.
How can I do that?
Thanks in advance,
First, use the closest
instead of parents
, as you have multiple .formContainerDiv
Second, after finding .formContainerDiv
with $(div.find("input:textbox")[0]).val()
and $(div.find("input:checkbox:checked")[0]).val()
locate the desired
To loop through all the checked checkboxes in CheckBoxListLoginUsers:
$.each($("#CheckBoxListLoginUsers :checked"), function(){
//value of the checkbox is $(this).val();
});
To get the value of TextBoxNote:
$("#TextBoxNote").val();
精彩评论