user354625
user354625

Reputation: 557

How to get the input and textarea values on change function using jquery

$('#filedset').find("select, input, textarea").change(function() { alert($(this).val()); });

if I use this code when I change anything on my dropdownlistbox I am getting alert but when I change anything on my Input or textarea changed text i am getting on alert?

is that something i am doing wrong?

thanks

Upvotes: 1

Views: 1920

Answers (1)

Nick Craver
Nick Craver

Reputation: 630429

The change events for these fire when they lose focus normally (e.g. click outside), if you want the handler to execute as you type, I recommend using the .keyup() event instead (so you get the right value, keydown would be the value without the current key taken into account).

Like this:

$('#filedset').find('select, input, textarea').bind('change keyup', function() {
   alert($(this).val());
});

Or if you have lots of and/or dynamic elements, you can use .delegate(), like this:

$('#filedset').delegate('select, input, textarea','change keyup', function() {
   alert($(this).val());
});

Upvotes: 1

Related Questions