I have many checkboxes with same class name and below each there is a hidden date field.
I need to show the div with the date field and select different date. in the begging I need to add 30 days from today when the checkbox is checked by default, then the user can change the date.
When I click to first choice and change the date is ok....but when I click to another the first date field takes the default value. Any suggestions?
html
@foreach (var item in Model)
{
<tr>
<td>
<div>
@Html.CheckBox(item.Title, new { @class = "chkPages", Value = item.ID }) @item.Title
</div>
<div class="extrafields">
<div class="DurationDisplayDate">
<input name="DurationDisplayDate" class="DurationDisplayDate" />
</div>
</div>
</td>
</tr>
-----------------------------
$('.chkPages').change(function () {
if (this.checked)
{
var dateStr = new Date();
dateStr.setDate(dateStr.getDate() + 30)
dateStr = dateStr.getDate() + "/" + (dateStr.getMonth() + 1) + "/" +
dateStr.getFullYear();
$(this).closest('div').next('.extrafields').fadeIn('slow');
//How can I change the next input field?
$(".DurationDate").val(dateStr);
}
else {
dateStr = "";
$(this).closest('div').next('.extrafields').fadeOut('slow');
$(".DurationDate").val(dateStr);
}
[<>]tool.DurationDate(which will select all elements with that class) but there's no way to know for sure with the info currently included in the question.findthe appropriate element(s) inside that.