0

For example, I want to set inputbox value in Bing Microsoft Translator , I can use:

 $('#tta_input').val('something')

But translation event are not triggered, it just triggered when I use keyboard input something, so there is any way to trigger translation event when I use $('#tta_input').val('something') to change inputbox text?

4b0
  • 21,981
  • 30
  • 95
  • 142
Haaaaa
  • 1

2 Answers2

0

So, you need to trigger the keypress event when the text was changed. Try the following things -

$("#tta_input").on("change paste keyup", function() {
    var e = $.Event("keypress", {which: 13});
    $(this).trigger(e);
});

To check the code:

$('#tta_input').on('keypress', function(e){
    console.log(e.which+' -- KeyPress event Fired');
});
Daniel Smith
  • 1,626
  • 3
  • 29
  • 59
0

You need to trigger that function on setting value by $('#tta_input').val('something') which you are using for translation on keyboard event.

E.G

$("#tta_input").on("keyup", function(e){
    // Your logic of translate
});

And when you setting value by .val() then you should do this

$("#tta_input").val("xyz").trigger('keyup');
Shahjahan
  • 542
  • 5
  • 12