# Conditional Card Creation with JavaScript

**URL:** <https://forums.ankiweb.net/t/conditional-card-creation-with-javascript/13450>\
**Category:** Card Design\
**Created:** [September 18, 2021, 4:13pm UTC](https://forums.ankiweb.net/t/conditional-card-creation-with-javascript/13450 "2021-09-18T16:13:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jolarin](https://avatars.discourse-cdn.com/v4/letter/j/ea666f/32.png) [@Jolarin](https://forums.ankiweb.net/u/Jolarin)\
**Post date:** [September 18, 2021, 4:13pm UTC](https://forums.ankiweb.net/t/conditional-card-creation-with-javascript/13450/1 "2021-09-18T16:13:13Z")

</div>

Hi there,

I am trying to figure out a way of creating cards only if a script provides a certain value. Any thoughts on how to implement that?

Any ideas are highly appreciated. 🙂

---

<div class="post-metadata">

**Author:** ![Rumo](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/rumo/32/1505_2.png) [@Rumo](https://forums.ankiweb.net/u/Rumo)\
**Post date:** [September 18, 2021, 4:39pm UTC](https://forums.ankiweb.net/t/conditional-card-creation-with-javascript/13450/2 "2021-09-18T16:39:56Z")

</div>

Card creation is done on the backend. A card is created if the evaluation of field replacements on the front side yields any text. Anything else, including script tags, is treated as literal text and not evaluated in any way.  
Maybe if you explain your intentions, someone can come up with another way to achieve your goal.

---

<div class="post-metadata">

**Author:** ![Jolarin](https://avatars.discourse-cdn.com/v4/letter/j/ea666f/32.png) [@Jolarin](https://forums.ankiweb.net/u/Jolarin)\
**Post date:** [September 18, 2021, 8:24pm UTC](https://forums.ankiweb.net/t/conditional-card-creation-with-javascript/13450/3 "2021-09-18T20:24:29Z")

</div>

My goal is to recreate the function of Cloze Overlapper with Closet for Anki to be able to use it in different card types. To do this, I want to read one specific line from a field at a time and write it as a Cloze. (Regarding this, I’m still missing a solution aswell). Since Closet makes the clozes dependent on the card number of the note, you have to hard-code that in advance (as far as I can tell). This is not a problem, but then all cards are always created (e.g. always 10 cards), even if the last cards have no content. To prevent this, I am looking for a way to create the affected cards only if actually row x exists. Hope this makes sense.

---

<div class="post-metadata">

**Author:** ![matta](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/matta/32/5126_2.png) [@matta](https://forums.ankiweb.net/u/matta)\
**Post date:** [September 18, 2021, 11:47pm UTC](https://forums.ankiweb.net/t/conditional-card-creation-with-javascript/13450/4 "2021-09-18T23:47:34Z")

</div>

Is there a field, upon which you can base your card? If that field is empty, you do not display anything else, and so the card is empty/clear and Anki will not display it?

{{# my\_control\_field }}  
{{ Front }}  
{{/ my\_control\_field }}

If that does not suit, have a look at [this post](https://suspicious-galileo-91919d.netlify.app/blog/conditional-formatting-based-on-field-content-for-anki-flashcards/).

---

<div class="post-metadata">

**Author:** ![werner](https://avatars.discourse-cdn.com/v4/letter/w/f4b2a3/32.png) [@werner](https://forums.ankiweb.net/u/werner)\
**Post date:** [October 6, 2021, 5:16pm UTC](https://forums.ankiweb.net/t/conditional-card-creation-with-javascript/13450/5 "2021-10-06T17:16:06Z")

</div>

I think I had the same question on reddit a while ago:

> **[r/Anki - Selective Card Generation based on content of field?](https://www.reddit.com/r/Anki/comments/nhblpx/selective_card_generation_based_on_content_of/)**
>
> 1 vote and 2 comments so far on Reddit

I’m afraid it doesn’t work.

Maybe this deck could provide a workaround:  
[https://ankiweb.net/shared/info/1637056056](https://ankiweb.net/shared/info/1637056056)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/1X/8f1279ababc5879d54e4838989f606cfe55af8c7.jpeg) [@system](https://forums.ankiweb.net/u/system)\
**Post date:** [May 1, 2023, 7:38am UTC](https://forums.ankiweb.net/t/conditional-card-creation-with-javascript/13450/6 "2023-05-01T07:38:35Z")

</div>

Closed on May 1, 2023, 7:38am UTC


