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

Asked

Viewed 207 times

4

I suppose my method:

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

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

I tried a lot and nothing:

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

http://jsfiddle.net/Lyqu4s92/

Expected behaviour:

When entering a character in the quantity field, a function must be called that calculates the value and quantity fields to play in the total field. When starting the page this function has to be called as well. The real case is this: a field with value, another with quantity and another with 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.

  • I couldn’t quite understand what you meant but in fiddle this working in change

2 answers

6


  • Weird. In my real case it doesn’t work straight. It only works when I click with the mouse on the input, then it calls the function. I have no function to click on my js.

  • What browser? Does my Chrome work.

  • Forget it. It was stupid of me here. It worked well, thank you!

2

If the goal 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();
  • Just to save code anyway.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.