How to force the '.on (' input ') method via script?

4

I guess my method:

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

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

I tried several and nothing:

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

link

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 the total empty. 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.

    
asked by anonymous 03.09.2014 / 19:46

2 answers

6

You came close to the fiddle:

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

link

    
03.09.2014 / 19:58
2

If the purpose is simply to call the function, why not give it a name and call it directly?

function callback(){
    alert("oi");
}
$(document).on("input", "#textbox", callback);
callback();
    
03.09.2014 / 20:00