开发者

Can the value of one select box change the value of/what is default in another checkbox and make it disabled?

I have 2 select boxes, "#Country" and "#StateAbbreviation" if a user selects a country other than USA - .val="USA" in the #Country select box, I need to change the value in "#StateAbbreviation" to OTHER/INTL. - val="IT" an开发者_如何学God make it disabled.

Why doesn't this work?

$("#Country").change(function() {
  if($(this).val() != 'USA') {
    $("#StateAbbreviation").val() == 'IT'.attr("disbled", true);   
  }
});

Kane Leins


You need to change it a bit, like this:

$("#Country").change(function() {
  if($(this).val() != 'USA') {
    $("#StateAbbreviation").val('IT').attr("disabled", true);   
  } else {
    $("#StateAbbreviation").val('').attr("disabled", false); 
  }
});

When setting a value, the call is .val(newValue), otherwise you're trying to set a function to a string, and call a function that doesn't exist on a string...causing a few errors.

This also resets the #StateAbbreviation <select> and re-enables if it is "USA".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜