Modifying #typeAns contents with JS

I am trying to modify the answer typed on the front of a card using JS, but it doesn’t seem to work very consistently.

For example, I put on a card an html button, which types ‘a’ into the card input field (the Type answer into the card setting is on) using the following script:

document.getElementById('typeans').value += 'a';

If I press this button, then also type ‘b’ using the phone on-screen keyboard and submit the answer by pressing “Show answer”, the back of the card shows that the typed answer is “ab” (as expected).
If, however, I first type ‘b’ with the phone keyboard, then use html button to add ‘a’ and submit the answer, the back of the card shows, that only “b” was submitted.

In general, it seems like AnkiDroid uses a separate variable to store what was typed into the input field and updates its value only when a key is pressed on the Android keyboard.

So I’d like to ask, is there any way to ensure that everything typed into the input field would always get carried to the back of the card? I wasn’t able to find any relevant functionality in the API.

1 Like

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