Answer Feedback: Javascript bypassed if quote mark in Answer?

Continuing the discussion from How to have instant type:answer feedback?:

Hi there! The script that provides answer feedback works perfect until I have quotation marks in the Answer field. Normally, as soon as I start typing, the color changes to let me know if I am good so far. However, if there are quote marks in the Answer field, as soon as I start typing the color remains the same. No feedback. Does anyone know why this is happening within Javascript? And, can it be resolved? Thanks!

Thank you so much for your solution hkr in the original discussion: How to have instant type:answer feedback?
It worked!!

It has to do with how JavaScript (and any other programming language) is parsed. A quote character like `, " or ’ usually marks the beginning of a string literal. If there’s an opening quote, the next instance of that character will be interpreted as the end of that string literal.

When you got this in your card template:

var fieldContent = "{{Field}}";

… and your field contains a double quote, there will be a syntax error, because all the text after that quote is interpreted as JavaScript. Same goes for ’ and `.

Hikaru’s solution from the other thread avoids this issue, because Anki will not insert the field content directly into your script, but inside an HTML element.

It is the recommended way to make field content available to JavaScript.


Thank you so much for answering my question. I really appreciate it. :+1:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.