Detecting value change of input[type=text] in jQuery

ID : 20201

viewed : 2

Tags : jqueryjquery

Top 5 Answer for Detecting value change of input[type=text] in jQuery

vote vote

98

Update - 2021

As of 2021 you can use input event for all the events catering input value changes.

$("#myTextBox").on("input", function() {    alert($(this).val());  }); 

Original Answer

just remember that 'on' is recommended over the 'bind' function, so always try to use a event listener like this:

$("#myTextBox").on("change paste keyup", function() {    alert($(this).val());  }); 
vote vote

86

Description

You can do this using jQuery's .bind() method. Check out the jsFiddle.

Sample

Html

<input id="myTextBox" type="text"/> 

jQuery

$("#myTextBox").bind("change paste keyup", function() {    alert($(this).val());  }); 

More Information

vote vote

72

Try this.. credits to https://stackoverflow.com/users/1169519/teemu

for answering my question here: https://stackoverflow.com/questions/24651811/jquery-keyup-doesnt-work-with-keycode-filtering?noredirect=1#comment38213480_24651811

This solution helped me to progress on my project.

$("#your_textbox").on("input propertychange",function(){     // Do your thing here. }); 

Note: propertychange for lower versions of IE.

vote vote

70

you can also use textbox events -

<input id="txt1" type="text" onchange="SetDefault($(this).val());" onkeyup="this.onchange();" onpaste="this.onchange();" oninput="this.onchange();">  function SetDefault(Text){   alert(Text); } 

Try This

vote vote

55

Try this:

Basically, just account for each event:

Html:

<input id = "textbox" type = "text"> 

Jquery:

$("#textbox").keyup(function() {      alert($(this).val());   });   $("#textbox").change(function() {  alert($(this).val());   });  

Top 3 video Explaining Detecting value change of input[type=text] in jQuery

Related QUESTION?