jquery - Detect if Dropdown has been changed by Javascript function -


i have javascript function auto-populates form fields based on available list of addresses. if user selects option country other us, not going require zip code / state fields in our form gets populated (all "required" validation handled through "data-required=true"). form dynamically generated, cannot use .change() method people suggesting.

i have "change" listener setup remove "data-required" attribute, works if click country dropdown , select different country. however, not work when javascript function changes same dropdown.

jquery( document ).ready(function() {      jquery('body').on('change','#cohcoun',function() {         if(jquery(this).val() == 'us') {             jquery('#cohpost').attr('data-required','true');             jquery('#cohste').attr('data-required','true');         } else {             jquery('#cohpost').removeattr('data-required');             jquery('#cohste').removeattr('data-required');         }     }); }); 

the function grabs hidden form values when selecting address, , applies them form. older code written in vanilla javascript, not jquery:

function setshipto(cipid) {     document.getelementbyid("cohname").value=document.getelementbyid("vshipto" + cipid + "hname").value;     document.getelementbyid("cohatn").value=document.getelementbyid("vshipto" + cipid + "hatn").value;     document.getelementbyid("cohad1").value=document.getelementbyid("vshipto" + cipid + "had1").value;     document.getelementbyid("cohad2").value=document.getelementbyid("vshipto" + cipid + "had2").value;     document.getelementbyid("cohad3").value=document.getelementbyid("vshipto" + cipid + "had3").value;     document.getelementbyid("cohste").value=document.getelementbyid("vshipto" + cipid + "hste").value;     document.getelementbyid("cohpost").value=document.getelementbyid("vshipto" + cipid + "hpost").value;     document.getelementbyid("cohcoun").value=document.getelementbyid("vshipto" + cipid + "hcoun").value;     document.getelementbyid("cohvia").value=document.getelementbyid("vshipto" + cipid + "hvia").value;     document.getelementbyid("cohshpr").value=document.getelementbyid("vshipto" + cipid + "hshpr").value;     document.getelementbyid("cociploc").value=document.getelementbyid("vshipto" + cipid + "ciploc").value;     document.getelementbyid("saveshiptofu").checked=false; } 

is there event listener can add detect if value changes javascript function? not want add code auto-populate function if possible

trigger change inside function dropdown change, may here

$('#cohcoun').trigger('change') 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -