Solved

JQuery code is not activating my DropDown

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP Web Development 6 68
how to use jquery variable in mysql query 20 74
AJAx/JQuery/JSON Error 3 38
Date Picker is picky (about something) 4 42
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.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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)
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…

734 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