Fórum

JQuery only partially working

Lee Chamberlain, modificado 7 Anos atrás.

JQuery only partially working

Junior Member Postagens: 92 Data de Entrada: 05/05/16 Postagens Recentes
My code is designed so that on change to the value 'Value Based' a select box changes the value (to one particular value) on another select box (to 'service' and disables it in order for the user not to change.

When the original select is changed to something that isn't 'Value Based' it un-disables the field.

This works perfectly the first time I do it. All subsequent times the disabled works (both on and off) as expected. However when the value is changed to 'Value Based' again it doesn't change the other select to 'service' but still disables the option on whatever happens to be in view at the time.



<aui:script>

$("#<portlet:namespace />orderType").change(function() {
var orderVar = $( "#<portlet:namespace />orderType" ).val();
if (orderVar == 'Value Based'){
		$("#<portlet:namespace />productType option[value='service']").attr("selected", true);
		
		$("#<portlet:namespace />productType").attr("disabled", true);
	}
	else {
		$("#<portlet:namespace />productType").attr("disabled", false);
	}
})
</aui:script>