Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function() {
  2.     //first, detect when initial DD changes
  3.     $("##Account_Code").change(function() {
  4.         //get what they selected
  5.         var selected = $("option:selected",this).val();
  6.         console.log("Selected:" + selected);
  7.         //no matter what, clear the other DD
  8.         //Tip taken from: http://stackoverflow.com/questions/47824/using-core-jquery-how-do-you-remove-all-the-options-of-a-select-box-then-add-on
  9.         $("##Sub_Account_Code").children().remove().end().append("<option value=\"\">Select a Sub Account Code</option>");
  10.         //now load in new options if I picked a state
  11.         if(selected == "") return;
  12.         $.getJSON("getAccountCodes.cfc?method=getSubAccountCodes&returnformat=json",{"account_code_id":selected}, function(res,code) {
  13.             var newoptions = "";
  14.             for(var i=0; i<res.length; i++) {
  15.             //In our result, ID is what we will use for the value, and NAME for the label
  16.             newoptions += "<option value=\"" + res[i].Account_Code_ID + "\">" + res[i].Account_Code + "</option>";
  17.             $("##Sub_Account_Code").children().end().append(newoptions);
  18.         }
  19.     });
  20. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement