开发者

Question on .submit and reloading form values AFTER the submit button is clicked

I am using jQuery 1.4.3 and have a newbie question.

In the foll开发者_开发知识库owing .submit function, I grab the value of the selected option in the facilityCodes dropdown list after I click the submit button and then during the submit function, select the facilityCode again in the dropdown list and then disable the list so that the user cannot change it. However, the situation is when I reload the page after the submit button is clicked the dropdown defaults to the first option and the list is enabled. I apparently am not understanding how .submit works so that I'm selecting the option I'm defining in my code and then disabling the list AFTER the page reloads. My question is what am I doing wrong? Am I using the wrong event?

Any help/direction would be greatly appreciated. Thank you.

Here is my code:

    $(function() {
        $("#ARTransferForm").submit(function() {
            var msgsCount = 0;

            var facilityCodeValue = $("#ARTransferForm\\:facilityCodes option:selected").val();
alert("facilityCodeValue = " + facilityCodeValue);
            if (facilityCodeValue == 0) {
                alert("To Facility Code must be selected");
                msgsCount++;
            } else {
                $('select[id$=facilityCodes]').val(facilityCodeValue);
                $("#ARTransferForm\\:facilityCodes").attr("disabled", "disabled");
            }
                });
}); 


Refreshing the page will erase everything you've done with JavaScript prior to the page refresh. If you're looking to preserve states through page reloads, you'll need to use server side code, or set a cookie.


The submit event is called on the current page when the form is about to post. You'll need to pass along a value (hidden field) that is checked on form load that you can check to determine if the list should be disabled.

Update:

On page load, you'll want to check to see if this is a repost where the hidden field id="disable_select" was set set during the post. If so, then you'll disable the form.

$(function(){
    if ($('#disable_select').val() == '1') {
        $("#ARTransferForm\\:facilityCodes").attr("disabled", "disabled");
    }
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜