Skip to content Skip to sidebar Skip to footer

Jquery Listen For All Text Input Changes

I have an input element within a form which I would like to be able to extract its value when the value changes. Take a look at this Fiddle: http://jsfiddle.net/spryno724/WaBzW/1/.

Solution 1:

$(document).ready(function() {
    $('input.clear').click(function() {
        $('input.input').val('');
        $('p.display').text('The value of the text input is: ');
    });

    $('input.input').on('keyup change', function() {
       $('p.display').text('The value of the text input is: ' + $(this).val());
    });
})​

DEMO 1

Probably this solution may help you:

$(document).ready(function() {
    $('input.clear, input[type=reset]').on('click', function() {
        $('input.input').val('').change();
        $('p.display').text('The value of the text input is: ');
    });

    $('input.input').on('keyup change', function() {
        $('p.display').text('The value of the text input is: ' + $(this).val());
    });
});​

DEMO 2

Solution 2:

This question is an exact duplicate of another. See the answer with the highest number of up-votes as the answer to my question:

JS Events: hooking on value change event on text inputs

Solution 3:

Override val method of jQuery

HTML

<input id='myInput' name='myInputField' value='v1'>

JS

var myInput = $('#myInput');

//this will not trigger the change event
myInput.val('v2');

//override val methodvar oldVal = myInput.val;
myInput.val = function(value){
   var returnVal = oldVal.call(this,value);
   myInput.change();
   return returnVal;
}

// this will trigger the change event// myInput.val is overridden
myInput.val('v3');

NOTE this will work only if val method is called from myInput variable

Solution 4:

Try

$('#input').live('change',function() {         })

Post a Comment for "Jquery Listen For All Text Input Changes"