I am developing an ASP .Net MVC 3 application using C# and SQL Server 2005.
I am using also Entity Framework and Code First Method.
In a view, I have 2 checkbox and DropDownList.
I want when I check the checkbox, the DropDownList and the other checkbox became DISABLED.
I use a javascript in order to do that.
The checkbox is perfect , it became disabled but I still have a problem with DropDownList.
This is the code :
<div>
<input type="checkbox" name="option1" value="Poste Initial" id= "chkMain" />Poste Initial<input type="checkbox" name="option2" value="Poste Final" id= "chkFirst" onclick="test2();"/>Poste Final</div>
<div><%:Html.Label("Poste Suivant :")%><%: Html.DropDownListFor(model => model.PosteSuivantSelected, Model.PostesItems); ID = "dd"%></div>
<script type="text/javascript">
function test2() {
var chkMain = document.getElementById('chkMain');
var chkFirst = document.getElementById('chkFirst');
var dd = document.getElementById('dd');
if (chkFirst.checked) {
chkMain.disabled = 'disabled';
dd.disabled = 'disabled';
}
else {
chkMain.disabled = false;
}
}
</script>
I had a Compilation Error in the line of DropDownList