Reputation: 46222
I have a some textboxes and a drop down. If the user does not have permission to modify them, I like to show a message and undo what they selected in teh case of a drop down or to undo what they types - in the case of a text box.
I tried the following for a drop down but did not work:
$('#ReasonDropDown').change(function () {
if (permission == "False") {
alert("You do not have permssion to make to modify this field.");
event.preventDefault();
return false;
}
});
It simply did not undo what I had selected.
Upvotes: 1
Views: 553
Reputation: 87073
You can try like below and it will works for any number of select
element.
$('select').attr('data-default', function() {
return this.value;
}).change(function(e) {
if (permission == 'False') {
alert('You do not have permission to modify this field.');
this.value = $(this).data('default');
}
});
And also can do similar for text
fields.
Upvotes: 1