Solved

JQuery code is not activating my DropDown

Posted on 2013-06-20
4
333 Views
Last Modified: 2013-06-21
I have a web form that has a dropdown that is disabled when the form is first displayed.  When the user enters a date in another textbox, a javascript function is called to enable the dropdown.  I've stepped through the code with a debugger to validate that it is executing but my dropdown is still disabled.  Not sure what I'm doing wrong and any help is greatly appreciated.  Relevant parts of my code is displayed below.

Hidden field referenced in JavaScript
    <asp:HiddenField ID="SuperUserFlag" runat="server" value="0" ClientIDMode="Static" />

I have verified that this hidden field is being set to 1 in my code behind.  I see the value in the debugger and when I view the source.

Open in new window


Field definition
                <tr>
                    <td>Promotion Date:</td>
                    <td><asp:TextBox ID="txtPromotionDate" ClientIDMode="Static" onchange="ActivatePromotionReasonDD()" runat="server" MaxLength="20" Text="" Enabled="False" BorderStyle="None"></asp:TextBox></td>
                    <td>Reason:</td>
                    <td>
                        <asp:DropDownList ID="ddPromotionReason" runat="server" 
                            AppendDataBoundItems="True" CausesValidation="True" ClientIDMode="Static" Enabled="False">
                                <asp:ListItem Value="">-- Choose Promotion Reason --</asp:ListItem>
                        </asp:DropDownList>
                    </td>
                </tr>

Open in new window


Script
    <script type="text/javascript">
        $(function () {
            var setActiveTab = $('#DisplayHiddenSelectTab').val();
            if (setActiveTab == 1)
                $('#tabs').tabs({ selected: 0 });
            else
                $('#tabs').tabs({ selected: 1 });

            // If Promotion Date is valued, activate Promotion Reason Drop Down
            ActivatePromotionReasonDD();
        });

        function ActivatePromotionReasonDD() {
            var SU = $('#SuperUserFlag').val();

            // Only activate drop down if user is Super User
            if (SU == 1) {
                var dDate = $('#txtPromotionDate').val();
                if (dDate != null) {
                    // Activate Promotion Reason Drop Down
                    $('#ddPromotionReason').attr("enabled", true);
                }
                else {
                    // Disable Promotion Reason DropDown if Promotion Date removed
                    $('#ddPromotionReason').attr("enabled", false);
                }
            }
        }

    </script>

Open in new window


No errors are reported on the page.
0
Comment
Question by:dyarosh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39264649
who have this ID : DisplayHiddenSelectTab

you're hidden id is : SuperUserFlag
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39264683
$('#ddPromotionReason').removeAttr('disabled'); // enable
$('#ddPromotionReason').attr("disabled", true); // disable
0
 
LVL 4

Expert Comment

by:AnuTiji
ID: 39265187
$('#ddPromotionReason').removeAttr('disabled'); // enable

To Disabled a dropdown set the value of "disabled" attribute to "disabled"

$('#ddPromotionReason').attr("disabled", "disabled"); // disable
0
 

Author Closing Comment

by:dyarosh
ID: 39265515
Thank you.  That worked.
0

Featured Post

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question