I cant get this to work. I am trying to replace certain characters when a key is pressed. It works fine when I use the variable replace_list instead of replace_list["russian"], but I need different "replace lists" for other things. What am I doing wrong?
<script type="text/javascript" src="javascript/jquery.js"></script>
<input id=answer>
<script>
replace_list = ["russian": {'a' : 'b', 'c' : 'd'}];
$(document).ready(function () {
$("#answer").keydown(function () {
var text = $(this).val();
$.each(replace_list["russian"], function (index, value) {
if (index == text.substring(text.length - value.length)) {
$("#answer").val(text.substring(0, text.length - value.length) + value);
}
});
});
})
</script>
replace_list[0] = ...without having first definedreplace_listthat will cause an error. You can fix this by first creating an array -var replace_list = []- or by making your assignment an array assignment:var replace_list = [{ ... }]. Other than that, your code does not seem to produce any meaningful difference in outcome depending on whether your object is placed atreplace_listorreplace_list[0].