jquery detect when input text field changed

Posted on 2012-09-17
Medium Priority
Last Modified: 2012-09-17
Hello Experts,

I have a simple input text field:

<input type="text" name="filter" id="filter">

Open in new window

Then, to detect whether the field has been altered, I use:

            var filter = Trim($(this).val().toLowerCase());

Open in new window

This works for all characters except delete.
How can I include this for delete etc.

I tried keydown, but the filter gives the result of the value of the text box before it was modified.  I need to make sure that the above code is triggered when any data is deleted.

Many thanks in advance!
Question by:jagku
LVL 83

Assisted Solution

leakim971 earned 1000 total points
ID: 38405886
setTimeout(function() {
      if(window["oldfilter"]!=$('input#filter').val()) {
             window["oldfilter"] = $('input#filter').val();
             alert("field modified");
}, 500);

Open in new window

LVL 12

Accepted Solution

Chris earned 1000 total points
ID: 38405893
This works:

	$('input#filter').keyup(function() {   
		var filter = $.trim($(this).val().toLowerCase());

Open in new window


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

DOM Attributes and Properties treatment with jQuery 1.6 by Ivo Stoykov jQuery (http://jquery.com/) 1.6 introduces .prop() (http://api.jquery.com/prop/) and .removeProp() (http://api.jquery.com/removeProp/) methods which allow modifying or removi…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month8 days, 17 hours left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question