[Django]-Reference a HTML tag with javascript that was generated from django json schema

0👍

Finally figured out what was causing the issue. The DOM was not finished rendering the JSON Schema Form before the script was executing to call

var project_selection = document.getElementsByName("form[project]");

therefore wrapping the above script in a jquery ready function fixed the issue.

<script>
     $('document').ready(function(){
          var project_selection = document.getElementsByName("form[project]");
          console.log(project_selection);
          console.log(project_selection[0]);
     });
</script>

see more at: Javascript HTML collection showing as 0 length

2👍

Not entirely sure on this one, but you are using
getElementsByClassName, which is relevant to the class name of the element. Not the name. So for example:

<div class="cname"></div>

That is a class name, form elements have a name attribute that you can query via
var project_selection = document.getElementsByName("form[project]");

Leave a comment