开发者

jquery not refreshing the value of an element

I have an app in which i have two buttons. Each will generate a jquery UI dialog dynamically with

$("<div class='dialog' style='font-size:12px' />").load(base_url + "/students/edit_profile/load_new_emp_form").dialog(options);
}

 $("<div class='dialog' style='font-size:12px' />").load(base_url + "/students/edit_profile/load_new_edu_form").dialog(options);
    }

Both these dialogs have a form with a button of same id #actBtn. I have a common handler for this button since both dialogs have the same action of submitting their data. The common handler function is

$("#addBtn").live("click", function(){
    var pst = {};
    pst = $(this).parent().serializeArray();
    var clbk = $("#clbk").val();    
    var tbl = "";
    tbl = $("#tbl").val();
    $.post(base_url + "/general/insert_new_entity/" + tbl, pst, function(data){
        $("#" + clbk).click();
    });
});

As you can see this will just serialize the current form which is on display and that form will have an input hidden element with id as tbl specifying the table name where this form's data will go.

My problem is after loading one form the next time tbl name remains the same it is not getting updated with the current table name. any ideas why that is?

Update regarding ID:

I know that ID's are supposed to be unique and even in my case they are uniq开发者_Go百科ue. THough both the forms have elements of same ID, they cannot exist in the DOM at the same time. They are modal dialogs and there can be only one dialog opened at any point of time thus there can exist only one element in the DOM with the same ID.


ID's are, by definition, supposed to be unique. The fact that you have two is the first problem that needs to be resolved. Having multiple elements with the same ID causes unpredictable behavior.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜