I am using jQuery to disable a dropdownlist. It’s very strange — when I add a breakpoint in firebug it works fine! However, if I just run it I see it get disabled for a fraction of a second and then get reenabled!
Basically:
I want to disable the list if ($(“#MessageTypes”).val() == ‘Text To Speech’)
Not sure why its not sticking..
If I take out the $.get line it works fine.
Why would that reset it? Especially since I disable the list after that code?
Thanks in advance!
<script type="text/javascript">
$().ready(function () {
$("#MessageTypes").change(function () {
var sMessageType = $("#MessageTypes").val();
$.get('@Url.Action("GenerateMessageDesc")', { messageType: sMessageType }, function (data) { $('#MessageDesc').replaceWith(data); });
//Text To Speech Chosen
if ($("#MessageTypes").val() == 'Text To Speech') {
$("#MessageDesc").val('5'); //5 is TEXT ID from database -- prob not best practice
$("#MessageDesc").attr("disabled", true); //disable select
$("#MessageContent").removeAttr("disabled"); //Enable Message Content
}
});
});
Use
Or
This is an issue with synchronous v/s asynchronous execution. the lines after $.get continue executing without waiting for the response, unless it is a callback.