I want to check if a user submitted string is the same as the string in my answer key. Sometimes the words involve Spanish accents (like in sábado), and that makes the condition always false.
I have Firebug log $('#answer').val()
and it shows up as sábado
. (The á
comes from a button that inserts the value á
, if that matters) whereas logging the answer from the answer key shows sábado
(how I wrote it in the actual answer key).
I have tried replacing the á
in the answer key with a normal á
, but it still doesn't work, and results in a Unicode diamond-question-mark. When I do that and also replace the value of the button that makes the user-submitted á
, the condition works correctly, but then the button, the user string, and the answer string all have the weird Unicode diamond-question-mark.
I have also tried using á
in both places and it's no different from using á
. Both my HTML and Javascript are using charset="utf-8"
.
How can I fix this?
If you're consistently using UTF-8, there's no need for HTML entities except to encode syntax (ie <
, >
, &
and - within attributes - "
).
For anything else, use the proper characters, and your problems should go away - until you run into unicode normalization issues, ie the difference between 'a\u0301'
and '\u00E1'
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With