How to create dynamic ids for tags in django templates

Background: I have a dynamic table (as in I don't know its size/elements until runtime) where I am trying to populate a text area with a javascript function. To do this I plan on passing the text area's id along with the values I want to populate it with into the javascript function.

The problem is I am having trouble creating a dynamic id value for each text input field. This is how i am currently attempting to do this:

   {% with "input_"| as idName %}
        <input id="{{ idName }}" type="text" value="">
        <input type="button" hidden="TRUE" onclick="">
        {{ idName }}
            putTags({{ idName }}, {{ tags }});
   {% endwith %}

where the function putTags() will populate the text input's contents. Unfortunately this doesn't work, as it assigns everyone's id to "input_" without appending's value (and I have checked, has a correct id for each iteration). Am i doing something wrong? Is there an easier way to create these unique IDs?



You can try something like this

<input id="input_{{ }}" type="text" value="">
<input type="button" onclick="putTags('input_{{ }}', {{ tags }});">


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.