2

i have a form(id="search_options") and i tracking changes in form by:

    $("#search_options").change(function() { 
        // Bla Bla Bla
    });

In this form i have many inputs and one of is select(id="project_category") and i want to catch if user changed project_category select or another input. How can i done this ? Thanks

3 Answers 3

3

What you are looking to do could be accomplished 2 ways I can think of off the top of my head. First, Capture the change event for all input items in your form individually

$("#search_options input,#search_options select").change(function() { 
   // "this" is the input that has changed so you would check if it had id = "project_category" here        
});

Alternatively you could track the current value of the "project_category" on every change

var current_Project_Category = ""; 
$("#search_options").change(function() { 
        if(current_Project_Category != $(this).find("#project_category").val())
        { 
           //project category has changed so mark this as the current one 
           //also run any change code here
           current_Project_Category = $(this).find("#project_category").val()   
        }

    });
Sign up to request clarification or add additional context in comments.

Comments

2

There is a plugin made for exactly this purpose:

jQuery Form Observe

This plugin observes values of form elements. When end-user changes any values of input elements, observer shows which values were changed. And observer also alerts to users when they try to move out from the page before submitting changes.

Comments

2

Try this instead:

$("#search_options").find('input,select').change(function() {
    var changedId = $(this).attr('id');
    var newVal = $(this).val();
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.