Changing a select option with jquery

Changing a select option with jquery

I'm changing a select element from another select element with jquery, the code works perfectly once but doesn't after that.

Basically it's a simple, change a select option, if one particular value is selected change a different select option (to select one particular option and disable that field).

From the second time onwards the field still disables, but it doesn't select the desired option.

What am I missing here?

  1. $("#<portlet:namespace />orderType").change(function() {
  2. var orderVar = $( "#<portlet:namespace />orderType" ).val();

  3. if (orderVar == 'Value Based'){

  4. $("#<portlet:namespace />productType option[value='service']").attr("selected", true);
  5. $("#<portlet:namespace />productType").attr("disabled", true);
  6. }
  7. else {
  8. $("#<portlet:namespace />productType").attr("disabled", false);
  9. }
  10. })