Solved

JQuery code is not activating my DropDown

Posted on 2013-06-20
4
330 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
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

790 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