javascript – How to force '.on("input")' method via script?

Question:

I suppose my method:

$(document).on("input", "#textbox", function(){
    alert("oi");
});

What script can I force the alert("hi") call?

I tried several and nothing:

$("input#textbox").val("1");
$("#textbox").val("1").on("input");
$("#textbox").input("1");
$("#textbox").input("1").change();

http://jsfiddle.net/Lyqu4s92/

Expected behavior:

When typing a character in the quantity field, a function must be called that will calculate the value and quantity fields to play in the total field. When starting the page this function has to be called too. The real case is this: one field with value, another with quantity and another with an empty total. When opening the page, the quantity field will be by default value 1, the value field will vary and the total will be calculated on top of these two values.

Answer:

You came close in the fiddle:

$("#textbox").trigger("input");

http://jsfiddle.net/Lyqu4s92/1/

Scroll to Top