Solved

JQuery code is not activating my DropDown

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Echo'd values in dropdowns 6 28
DataTable column sorting incorrectly 2 17
[form-control] Retain values after a POST action 21 32
JS to redirect to prev page 8 18
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

740 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