Confirm Save during onchange of drop down

与世无争的帅哥 提交于 2019-12-25 00:50:58

问题


Onchange of select option I am confirming the user whether to save or not the changes. If user selects OK , I am submitting the form automatically.ie. onchange="if(confirm('Save?')){this.form.gridedit.click();} ". When user selects cancel it is populating the recently selected option. My problem is I have to populate the old value if user selects Cancel option from that confirmation message. Please help in this issue any one. Thanks


回答1:


Try this, don't think you can accomplish it without some manual work.

<script type="text/javascript">
var ddHelper = {
    previousIdx: null,
    store: function(e, dd) {
        this.previousIdx = dd.selectedIndex;
    },
    confirm: function(e, dd) {
        if(!window.confirm('Save?')) {
            window.setTimeout(function() { // Think you need setTimeout for some browsers
                dd.selectedIndex = ddHelper.previousIdx;
            }, 0);
        }
    }
};
</script>
<select onfocus="ddHelper.store(event, this)" onchange="ddHelper.confirm(event, this">
</select>



回答2:


If the input values come from any Database, load those again in the field when user press cancel.



来源:https://stackoverflow.com/questions/2130707/confirm-save-during-onchange-of-drop-down

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!