How to enable and disable drop down list by selecting radio button in ASP.NET

Mano Prathibhan C

I want to create a page in which whenever i select a particular radio item, a drop down list should be enabled and if some other item it selected the drop down list should be disabled.

This is my form script in ASP.NET

<form id="ticketbooking" class="book-ticket" runat="server">
    <asp:Label ID="mode" runat="server" class="label">Mode of Travel</asp:Label><br />
    <asp:RadioButton name="selector" ID="train" GroupName="travelmode" runat="server" value="tr"></asp:RadioButton>
    <asp:Label ID="forTrain" for="train" runat="server" class="label">Train</asp:Label> 
    <div class="check"></div>
    <asp:RadioButton name="selector" ID="air" GroupName="travelmode" runat="server" value="ar" OnCheckedChanged="air_CheckedChanged"></asp:RadioButton>
    <asp:Label ID="forAir" for="air" runat="server" class="label">Air</asp:Label> 
    <div class="check"></div><br />
    <asp:Label ID="airname" runat="server" class="label">Airline Name</asp:Label><br />
    <asp:DropDownList class="droplist" ID="airlist" runat="server" Enabled="false" Font-Size="20px">
        <asp:ListItem>Air India</asp:ListItem>
        <asp:ListItem>Kingfisher</asp:ListItem>
        <asp:ListItem>Jet Airways</asp:ListItem>
        <asp:ListItem>Spice Jet</asp:ListItem>
    </asp:DropDownList>
</form>

I have tried a few scripts as below but they wont work...

Method 1:

<script>
    $(document).ready(function () {
        $('input[name="selector"]').click(function () {
            if ($('input[name="selector"]').is(':checked')) {
                var radioValue = $("input[name='selector']:checked").val();
                if (radioValue == "tr") {
                    $("#airlist").prop("disabled", true);
                } else if (radioValue == "ar") {
                    $("#airlist").prop("disabled", false);
                }
            }
        });
    });
</script>

Method 2:

protected void air_CheckedChanged(object sender, EventArgs e)
{
    if (air.Checked == true)
    {
        airlist.Enabled = true;
    }
    else
    {
        airlist.Enabled = false;
    }
}

I tried both but its not working..when i click on the "Air" radio button the drop down list should be enabled..am i doing something wrong? need some suggestions please..i am still new to ASP.NET and not sure about how to work in this framework.

Faraz

For Method 1 put ClientIDMode="static" you JavaScript code will working fine LIKE

<asp:RadioButton ClientIDMode="static" name="selector" ID="train" GroupName="travelmode" runat="server" value="tr"></asp:RadioButton>

For Method 2 Put AutoPostback=true your C# will working fine LIKE

<asp:RadioButton AutoPostback="true" name="selector" ID="train" GroupName="travelmode" runat="server" value="tr"></asp:RadioButton>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to enable / disable drop down list of Spinner

From Dev

How to enable disable a select drop down list using radio buttons with angularjs?

From Dev

In radio group Selecting radio button as yes must enable a textview & selecting radio button as no must disable textview in android

From Dev

Tabs resetting after selecting drop down list in C# , ASP.net

From Dev

Tabs resetting after selecting drop down list in C# , ASP.net

From Dev

How to bind a datatable to drop down list in ASP.net MVC?

From Dev

How to save the drop down list selected index in asp.net?

From Dev

Selecting respective item in drop down list when edit button is clicked

From Dev

Selecting respective item in drop down list when edit button is clicked

From Dev

How to disable drop down list in JSP?

From Dev

Bind list to drop down in Asp.net

From Dev

Radio button and drop down list command to create register form

From Dev

Angular 2 - How to disabled button and enable it back until some value is selected in the drop down list?

From Dev

How to disable other drop down when selecting one from all drop down

From Dev

how to enable and disable a dropdown list based on whether a radio button is checked or not through jstl in jsp

From Dev

ASP.NET MVC: Click on a button to redirect based on drop down list's value

From Dev

I want to display the current time in different countries on selecting country name from a drop down list in asp.net

From Dev

How to toggle enable/disable input field based on radio button

From Dev

How to display an object property in a drop down list in VB.Net/C# and ASP.NET

From Dev

Script to disable a text box on selecting a radio button

From Dev

Jquery disable checkbox on radio button click with ASP.NET RadioButtonList

From Dev

Enable and Disable button based on drop-down selection. - Bootstrap 3

From Dev

How to enable or disable Button control on entering true regular expression validator in asp.net using jQuery

From Dev

How to use multiple conditions in asp.net Eval function to enable and disable a button in a templatefield?

From Dev

How to have one button do both "enable" and "disable" in ASP.net MVC

From Dev

enable or disable e.preventDefault of javascript for ASP:NET webform button

From Dev

How to get converted boolean value to show as selected value in the editable drop down list in asp.net gridview?

From Dev

How access selected value drop down list in asp.net mvc?

From Dev

how to make the drop down list to be visible for certain user only in asp.net?

Related Related

  1. 1

    How to enable / disable drop down list of Spinner

  2. 2

    How to enable disable a select drop down list using radio buttons with angularjs?

  3. 3

    In radio group Selecting radio button as yes must enable a textview & selecting radio button as no must disable textview in android

  4. 4

    Tabs resetting after selecting drop down list in C# , ASP.net

  5. 5

    Tabs resetting after selecting drop down list in C# , ASP.net

  6. 6

    How to bind a datatable to drop down list in ASP.net MVC?

  7. 7

    How to save the drop down list selected index in asp.net?

  8. 8

    Selecting respective item in drop down list when edit button is clicked

  9. 9

    Selecting respective item in drop down list when edit button is clicked

  10. 10

    How to disable drop down list in JSP?

  11. 11

    Bind list to drop down in Asp.net

  12. 12

    Radio button and drop down list command to create register form

  13. 13

    Angular 2 - How to disabled button and enable it back until some value is selected in the drop down list?

  14. 14

    How to disable other drop down when selecting one from all drop down

  15. 15

    how to enable and disable a dropdown list based on whether a radio button is checked or not through jstl in jsp

  16. 16

    ASP.NET MVC: Click on a button to redirect based on drop down list's value

  17. 17

    I want to display the current time in different countries on selecting country name from a drop down list in asp.net

  18. 18

    How to toggle enable/disable input field based on radio button

  19. 19

    How to display an object property in a drop down list in VB.Net/C# and ASP.NET

  20. 20

    Script to disable a text box on selecting a radio button

  21. 21

    Jquery disable checkbox on radio button click with ASP.NET RadioButtonList

  22. 22

    Enable and Disable button based on drop-down selection. - Bootstrap 3

  23. 23

    How to enable or disable Button control on entering true regular expression validator in asp.net using jQuery

  24. 24

    How to use multiple conditions in asp.net Eval function to enable and disable a button in a templatefield?

  25. 25

    How to have one button do both "enable" and "disable" in ASP.net MVC

  26. 26

    enable or disable e.preventDefault of javascript for ASP:NET webform button

  27. 27

    How to get converted boolean value to show as selected value in the editable drop down list in asp.net gridview?

  28. 28

    How access selected value drop down list in asp.net mvc?

  29. 29

    how to make the drop down list to be visible for certain user only in asp.net?

HotTag

Archive