<script type="text/javascript"> {% for field in prepopulated_fields %} document.getElementById("{{ field.field.auto_id }}").onchange = function() { this._changed = true; }; {% for dependency in field.dependencies %} document.getElementById("{{ dependency.auto_id }}").{% if dependency.field.choices %}onchange{% else %}onkeyup{% endif %} = function() { var e = document.getElementById("{{ field.field.auto_id }}"); if (!e._changed) { e.value = URLify({% for innerdep in field.dependencies %}{% if innerdep.field.choices %}document.getElementById("{{ innerdep.auto_id }}").options[document.getElementById("{{ innerdep.auto_id }}").selectedIndex].text{% else %}document.getElementById("{{ innerdep.auto_id }}").value{% endif %}{% if not forloop.last %} + ' ' + {% endif %}{% endfor %}, {{ field.field.field.max_length|default_if_none:"50" }}); } } {% endfor %} {% endfor %} </script>