Question

I am acheiving this via postback but that is adding a delay at my server so I want to handle this on the client side. Can anyone guide me how to disable one combobox on the clientside event of another combobox.

I have done so far:

function Enable() {
         alert("gfugsdugfsduigf");
         var ddl3 = document.getElementById("Cmbx1");
         var ddlValue3 = ddl3.options[ddl3.selectedIndex].value;
         if (ddlValue3 == "1") {
             document.getElementById('<%=Cmbx2.ClientID%>').disabled = false;
        }
        else {
            document.getElementById('<%=Cmbx2.ClientID%>').disabled = true;
        }

     }

In the page load I am writing:

Cmbx1.Attributes.Add("onChange", "Enable();");

But No success, even the control is not going to the function when I debug.

Was it helpful?

Solution

something like this maybe... ?

function pageLoad() // automatically called (and necessary to use when working with comboboxes)
{
        // add change event to cmbx1
        $find("<%=cmbx1.ClientID%>").add_propertyChanged(
                function (sender, e) {
                        if (e.get_propertyName() == 'selectedIndex') {
                                cmbx1_onChange();
                 }
        });
}

function cmbx1_onChange()
{
        // get selected value of box 1
        var cmbx1Value = $find("<%=cmbx1.ClientID%>").get_textBoxControl().value;

        // enable box 2 if selected value of box 1 is 1, else disable
        $find("<%=cmbx2.ClientID%>").get_textBoxControl().disabled = cmbx1Value != 1;
        $find("<%=cmbx2.ClientID%>").get_buttonControl() .disabled = cmbx1Value != 1;
}

except without all the indentation stripped

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top