javascript - Finding Changed Form Element With jQuery - Stack Overflow

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

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

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

Share Improve this question asked Jun 8, 2010 at 20:54 mTuranmTuran 1,8345 gold badges35 silver badges59 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

What you are looking to do could be acplished 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()   
        }

    });

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.

Try this instead:

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745520269a4631229.html

相关推荐

  • javascript - Finding Changed Form Element With jQuery - Stack Overflow

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

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信