I have a Django form with a number of dropdown menus, all of CharFields (before we go further--I think this problem could be solved with some additional models and some M2M relationships, but that idea has been squashed by the Powers That Be). I want to use javascript (ajax?) to change the options in the second field based on the value of the first.
Right now, I'm struggling with how to change the values at all. I have this:
<script>
$('#id_database_type').change(function(){
$('.asset-form').fields['monitoring_method'].widget.choices=[('test', 'test')]
});
</script>
but I'm getting an undefined error; $('.asset-form').fields
returns undefined. This was code I got from another post but I think it is supposed to go in the init
section of my form, which I don't think would do what I want it to do.