javascript - How do I disable input field when certain select list value is picked -
how disable , make input field text hidden when value selected select list? in code, need disable , make input text hidden when "united states" selected drop down.
my html: jsfiddle link
my javascript:
document.getelementbyid('billingcountrycode').onchange = function () { if(this.value != '840') { document.getelementbyid("billingstateprovince").disabled = true; document.getelementbyid("billingstateprovince").style.display="none" } else { document.getelementbyid("billingstateprovince").disabled = false; document.getelementbyid("billingstateprovince").style.display="block" } }
the problem fiddle have 2 elements same id. can there, change id on either state dropdown or text input. updated code might this, if name text input same 2:
document.getelementbyid('billingcountrycode').onchange = function () { if(this.value != '840') { document.getelementbyid("billingstateprovince").disabled = true; document.getelementbyid("billingstateprovince").style.display="none"; document.getelementbyid("billingstateprovince2").disabled = false; document.getelementbyid("billingstateprovince2").style.display="block"; } else { document.getelementbyid("billingstateprovince").disabled = false; document.getelementbyid("billingstateprovince").style.display="block"; document.getelementbyid("billingstateprovince2").disabled = true; document.getelementbyid("billingstateprovince2").style.display="none"; } }
Comments
Post a Comment