Solved

JQuery code is not activating my DropDown

Posted on 2013-06-20
4
324 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
Comment Utility
who have this ID : DisplayHiddenSelectTab

you're hidden id is : SuperUserFlag
0
 
LVL 58

Accepted Solution

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

Expert Comment

by:AnuTiji
Comment Utility
$('#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
Comment Utility
Thank you.  That worked.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Condidional <a href = ....> 1 22
jQuery or CSS 9 37
JavaScript error 1 31
Re-position the objects 7 45
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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)

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now