Currently, I am in the process of developing an application using ASP .Net MVC 3 with C# and SQL Server 2005.
Additionally, I am incorporating Entity Framework along with the Code First Method for this project
Within a specific view, there are 2 checkboxes and a DropDownList present
The desired functionality is that upon checking one checkbox, both the DropDownList and the other checkbox will become DISABLED.
To achieve this, a javascript script has been implemented
While the checkbox successfully gets disabled as intended, there seems to be an issue with disabling the DropDownList
Below is the code snippet:
<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>
However, there was a Compilation Error encountered in the line where the DropDownList is defined