i have a problem with hide and show a textbox based on a checkbox, because it is based on variable ids.
I know that the markActiveLink2(el) function is ok, because i can find the values of the chosen checkbox and textbox with the Console in Chrome. So for example if i choose the first checkbox the value is CloseDateCheck0. But somehow the second part of my javascript dont work.
Thank you for your help in advance.
javascript
//Hide and Show Close Date
//Set Variables
var CloseDateCheck_id = '';
var CloseDate_id = '';
//Define Variables, so it is known which Date i want to change
function markActiveLink2(el) {
CloseDateCheck_id = $(el).attr("id");
CloseDate_id = CloseDateCheck_id.replace("CloseDateCheck", "CloseDate");
}
//Hide and show Date based on the variable ids
$(document).ready(function(){
$("#"+ CloseDateCheck_id).click(function () {
//var $this = $(this);
if (this.checked) {
$("#"+CloseDate_id).show();
} else {
$("#"+CloseDate_id).hide();
document.getElementById(CloseDate_id).value = null;
}
});
});
.cshtml
@for (int i = 0; i < Model.OpenIssue.Count(); i++)
{
@*...*@
<b>Close Issue</b>
@Html.CheckBox("Finish", new { id= "CloseDateCheck"+i, onmousedown="markActiveLink2(this);"})
@Html.TextBoxFor(modelItem => modelItem.OpenIssue[i].CloseDate, "{0:dd.MM.yyyy}", new { @class = "datetype", type = "text", style = "width: 90px; display:none", id="CloseDate"+i })
@*...*@
}
processed html
<b>Close Issue</b>
<input id="CloseDateCheck0" name="Finish" onmousedown="markActiveLink2(this);" type="checkbox" value="true">
<input name="Finish" type="hidden" value="false">
<input class="datetype hasDatepicker" data-val="true" data-val-date="The field CloseDate must be a date." id="CloseDate0" name="OpenIssue[0].CloseDate" style="width: 90px; display:none" type="text" value="">
Aucun commentaire:
Enregistrer un commentaire