I have some paired values stored as a hashmap in my model, for example sake, we'll say the 'key' is a Manager's ID and the 'value' is the name of their department, so 'betty123' could be a key to a value 'IT', and 'dave345' could be a key for the value 'Finance'. This hashmap is populated from a database. In my form, I have two "Select" dropdown fields, one for "Department" (with fields which match the values in the hashmap), and one for "Manager ID". I want to autopopulate the "Manager ID" field when the "Department" field is changed, based on the values in the Hashmap. I understand that I can't access dynamically elements of the hashmap in a script, so, for example, I can't do this:
Because this code is dynamic based on the value of "department" at the time it's run, whereas the departmentHash object is generated when the page is loaded.
Is there some other way I can do this? Am I approaching it the wrong way? FWIW, I'm using Spring 4.1.1 and jQuery 1.8. I understand the conceptual block with code I wrote above, but I can't for the life of me think of an obvious solution although I'm sure this is a fairly commonplace problem in web development.
For example, you likely want to end up with something like:
Hmm, ok, but the pairings I need have to be pulled from a database, so I can't just hardcode them directly into the page (well, I could, it would just require more manual maintenance over the webpage), but is there any way at all to do it while pulling the values in from the database via the model?
Ryan Kostrzewa wrote:Hmm, ok, but the pairings I need have to be pulled from a database, so I can't just hardcode them directly into the page
Perhaps you might benefit from reading these articles: