javascript - How to create dynamic ids for tags in django templates - Stack Overflow

Background: I have a dynamic table (as in I don't know its sizeelements until runtime) where I am

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_"|add:applicant.id as idName %}
        <input id="{{ idName }}" type="text" value="">
        <input type="button" hidden="TRUE" onclick="">
        {{ idName }}
        <script>
            putTags({{ idName }}, {{ tags }});
        </script>
   {% 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 applicant.id's value (and I have checked, applicant.id has a correct id for each iteration). Am i doing something wrong? Is there an easier way to create these unique IDs?

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_"|add:applicant.id as idName %}
        <input id="{{ idName }}" type="text" value="">
        <input type="button" hidden="TRUE" onclick="">
        {{ idName }}
        <script>
            putTags({{ idName }}, {{ tags }});
        </script>
   {% 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 applicant.id's value (and I have checked, applicant.id has a correct id for each iteration). Am i doing something wrong? Is there an easier way to create these unique IDs?

Share Improve this question asked Apr 10, 2013 at 17:40 JamesJames 1972 silver badges13 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

You can try something like this

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744145141a4560385.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信