Click here to Skip to main content
14,452,838 members
Rate this:
Please Sign up or sign in to vote.
Hi,

I need to enable/disable dropdown on another dropdown selection. I wrote below code to do the same but its working fine on my system with all browser compatibility but not on other machine with IE8.
Please suggest .

///enable disable Payment method dropdown on moneysource  dropdown change
if (stepName == "PaymentDetails") {
    $("select").each(function () {
        if ($(this).parent().attr("controlName") == "Money source") {
            $(this).change(function () {
                enableDisablePaymentMethod($(this));
            });
            enableDisablePaymentMethod($(this));
        }
    });
}

///enable disable Payment method dropdown on moneysource  dropdown change
function enableDisablePaymentMethod(dropdown) {
    var length = dropdown.children("option").length;
    var val = dropdown.val();
    $("select").each(function () {
        if ($(this).parent().attr("controlName") == "Payment method" || $(this).parent().attr("controlName") == "Payment Method") {
            if (length == 0 || val == "") {
                $(this).prepend('<option value="Select Money Form" selected="selected">Select Money Form</option.');
                $(this).attr("disabled", "disabled");
            }
            else {
                $(this).removeAttr("disabled");
                $(this).children("option[value='']").remove();
                $(this).children("option[value=Select Money Form]").remove();

            }
        }
    });
}
Posted
Updated 27-May-19 1:05am
Comments
Sandeep Mewara 7-May-12 4:21am
   
Is there any JS error on other system?
Rate this:
Please Sign up or sign in to vote.

Solution 1

Hi,

Please try this code

\\Javascript

$('#ParentDD').change(function(){
var SelectedDD = $(this).val();
if(SelectedDD == "P1")
{
var x=document.getElementById("ChildDD");
    x.disabled=true;
}
else if(SelectedDD == "P2")
{
var x=document.getElementById("ChildDD");
    x.disabled=false;
}
});


\\Client Code
<SELECT id="ChildDD">
 <OPTION > C1 </OPTION>
 <OPTION > C2 </OPTION>
</SELECT>

<SELECT id="ParentDD">
 <OPTION > P1 </OPTION>
 <OPTION > P2 </OPTION>
</SELECT>
   
Comments
charu.singh 7-May-12 6:12am
   
Thanks for the suggestions , there is no error generated at other machine , its just stop disabling child dd on parent dd selection, while its working at my machine .

Note : I need to disable child dd on first page load and it shud enable on parent dd selection only.
my code the controls are generated dynamically and don't have its fix client id .
Rate this:
Please Sign up or sign in to vote.

Solution 2

Here is my code :

Edit fiddle - JSFiddle[^]


How to change the condition like if i select "I have -> 3 Compact" & "I want -> Should be allow me to select 3 Regular and 3 Triple " Now the condition like disable all my 3 based value.

Any help Thanks.
   
v4
Comments
OriginalGriff 27-May-19 6:39am
   
This is not a solution, and posting it as such reduces the chances of you getting any help. Plus, it's 7 years old, so the chances of anyone who might help seeing it are very low.

Post it as a new question, but give us better detail than that, and copy'n'paste your code instead of linking offsite - the later makes the automated system think you might be a spammer and that delays the posting until a human volunteer (or me in this case) reviews the case.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




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