Click here to Skip to main content
14,457,167 members

Disable selected option from dropdown

asbis asked:

Open original thread
HI
I have six dropdownlist with same values in my aspx page.If user selected first item from first dropdowlist then that selected item sholud be disabled from other dropdownlist.
user should select any option only once.

here is my code:-
This code is working properly in Mozila except IE7.I want it should work in IE7 also.
--- script----->
<script type="text/javascript">

        $(function () {
            
            $('select').each(function (cSelect) {
                $(this).data('stored-value', $(this).val());
            });
            
            $('.ddlselect').change(function () {
                var previousVal = $(this).data('stored-value'); //get previous selected value
                var selectedVal = $(this).val(); //get selected dropdown value 

                $(this).data('stored-value', selectedVal); //set new selected value

                var eleid = $(this).attr("id");
                $(".ddlselect").each(function () {

                    if ($(this).attr("id") !== eleid) {
                        $(this).parent().find('option[value="' + selectedVal + '"]:not(:selected)').attr('disabled', 'disabled');
                    }
                });
            });
        });
        
    </script>


-- controls---->
<asp:DropDownList ID="DropDownList_1" runat="server" CssClass="ddlselect">
       <asp:ListItem>1
       <asp:ListItem>2
       <asp:ListItem>3
       <asp:ListItem>4
       <asp:ListItem>5
       <asp:ListItem>6
       <asp:ListItem>7
       <asp:ListItem>8
       <asp:ListItem>9
       <asp:ListItem>10


   <asp:DropDownList ID="DropDownList_2" runat="server" CssClass="ddlselect">
       <asp:ListItem>1
       <asp:ListItem>2
       <asp:ListItem>3
       <asp:ListItem>4
       <asp:ListItem>5
       <asp:ListItem>6
       <asp:ListItem>7
       <asp:ListItem>8
       <asp:ListItem>9
       <asp:ListItem>10

   <asp:DropDownList ID="DropDownList_3" runat="server" CssClass="ddlselect">
       <asp:ListItem>1
       <asp:ListItem>2
       <asp:ListItem>3
       <asp:ListItem>4
       <asp:ListItem>5
       <asp:ListItem>6
       <asp:ListItem>7
       <asp:ListItem>8
       <asp:ListItem>9
       <asp:ListItem>10



Any idea how disable the option of dropdownlist in IE7.
Or we need to use specific version of jQuery for this.

Thanks
Ashish
Tags: Javascript, jQuery

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100