Reputation: 29
I have generated a MVC application in which I have created DateTimePicker control using html helper EditorFor control and JQuery.
Below is the line of DateTime picker control
@Html.EditorFor(model => model.ClosedTime)
Also I have one DropdowmFor control based on which selection I want to make EditorFor control as enable or disable.
Initially when my page loads I make the control disabled using below JQuery statement
$('#ClosedTime').attr('disabled', 'disabled');
This statement works fine and it disables the control, now as I said before I want to make the EditorFor control enable and disable based on the selection of DropdownFor control.
I tried this by writing below script.
$('#selectedRequestStatus').change(function () {
var selectedRequest = $(this).val();
if (selectedRequest == "C") {
//alert('Closed');
$('#ClosedTime').attr('disabled', 'enable');
}
else {
//alert('In Progress');
$('#ClosedTime').attr('disabled', 'disabled');
}
});
Where selectedRequestStatus is the Dropdown control as I mentioned before.
But this script doesn't work.
Please let us know your suggestions for the above issue.
Thanks in advance.
Upvotes: 0
Views: 1027
Reputation: 5510
It looks like your issue is in the jQuery... try this:
$('#selectedRequestStatus').change(function () {
var selectedRequest = $(this).val();
if (selectedRequest == "C") {
//alert('Closed');
$('#ClosedTime').removeProp('disabled');
}
else {
//alert('In Progress');
$('#ClosedTime').prop('disabled', 'disabled');
}
});
In HTML, the presence of the disabled
attribute makes the control 'disabled'. By removing it completely it enables the control.
Upvotes: 2