-1

I am having a little confusion in jquery regarding an onchange event of a text box. I am having a text box and a small jquery snippet to detect if the user has pasted something:

$("#testid").bind("paste",function(){ do something.})

Is there any function like paste which detects whenever there is a change in the text box? i.e, when a user inputs something, immediately call a function (not on submit), and do something. Any help is appreciated

digitalextremist
  • 5,952
  • 3
  • 43
  • 62
Parameswar
  • 1,951
  • 9
  • 34
  • 57

4 Answers4

1

Use .change function.

$("#testid").change(function(){ 
    //do something.
});

This works, if

  • user pastes something
  • user types
  • user deletes text

into/from the textbox. Globally, when textbox's value changes.

Jquery Documentation

aksu
  • 5,221
  • 5
  • 24
  • 39
0

You can use this. also check JSFiddle attached.

$("#txtBox").on('change', function(e){ 
    alert('txtBox has changed: ' + $(this).val());
});

http://jsfiddle.net/AUSd6/

Ben Pretorius
  • 4,079
  • 4
  • 34
  • 28
0

If you using latest jquery library, below script can be helpfull

$( "#testid" ).on( "change", function() {
  //do something.
});

For Detail visit http://api.jquery.com/on/

Pank
  • 13,800
  • 10
  • 32
  • 45
0

Following are 3 methods those are very helpful if you have to detect changes as soon as user presses keys on keyboard. Keydown,Keypress,Keyup

Keydown--> would be called when your keyboard key is down.

Keyup --> called when user leaves the key after typing the character.

keypress--> is called as soon as user press the key on the keyboard.

There is change method also but this is called when someone after typing the word in textbox or any field clicks any place on the page or moves to next input field.

here is code how to use them.

$("#yourcontrolId").keyup(function(){

});

similarly you can use others 2 as well. every function have two overloaded versions

Husrat Mehmood
  • 2,270
  • 1
  • 20
  • 22