Question

I can't re enable a option from my drop down. For some weird reasons I can disable but can't revert back. Is there any work around on this? I'm using SharePoint 2007

$(document).ready(function()
if($("#ctl00_m_g_98b27f90_2d47_4399_9f55_39944c5c3d72_ctl00_ctl04_ctl23_ctl00_ctl00_ctl04_ctl00_DropDownChoice option[value='Validating']")){
$("#ctl00_m_g_98b27f90_2d47_4399_9f55_39944c5c3d72_ctl00_ctl04_ctl23_ctl00_ctl00_ctl04_ctl00_DropDownChoice option[value='Analysis']").attr("disabled", "disabled");
}
else     
if($("#ctl00_m_g_98b27f90_2d47_4399_9f55_39944c5c3d72_ctl00_ctl04_ctl23_ctl00_ctl00_ctl04_ctl00_DropDownChoice option[value='Resolving']")){

$("#ctl00_m_g_98b27f90_2d47_4399_9f55_39944c5c3d72_ctl00_ctl04_ctl23_ctl00_ctl00_ctl04_ctl00_DropDownChoice option[value='Analysis']").removeAttr("disabled");
}
});
Was it helpful?

Solution

$("#ctl00_m_g_98b27f90_2d47_4399_9f55_39944c5c3d72_ctl00_ctl04_ctl23_ctl00_ctl00_ctl04_ctl00_DropDownChoice option[value='Validating']") 

Is a jQuery object, which is always a truthy value (even if nothing's selected). Therefore, the first if statement is always executed.

Instead, use $('blah').length to determine if anything was selected.

Though holy cow, find a better way to identify your DOM.

OTHER TIPS

You're missing an opening bracket on the ready callback.

$(document).ready(function() { <--- here
    if($("#ctl00_m_g_98b27f90_2d47_4399_9f55_39944c5c3d72_ctl00_ctl04_ctl23_ctl00_ctl00_ctl04_ctl00_DropDownChoice option[value='Validating']")){
        $("#ctl00_m_g_98b27f90_2d47_4399_9f55_39944c5c3d72_ctl00_ctl04_ctl23_ctl00_ctl00_ctl04_ctl00_DropDownChoice option[value='Analysis']").attr("disabled", "disabled");
    }
    else if($("#ctl00_m_g_98b27f90_2d47_4399_9f55_39944c5c3d72_ctl00_ctl04_ctl23_ctl00_ctl00_ctl04_ctl00_DropDownChoice option[value='Resolving']")){
        $("#ctl00_m_g_98b27f90_2d47_4399_9f55_39944c5c3d72_ctl00_ctl04_ctl23_ctl00_ctl00_ctl04_ctl00_DropDownChoice option[value='Analysis']").removeAttr("disabled");
    }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top