how to prevent to change selectbox value if i say no to confirm

后端 未结 4 1522
野趣味
野趣味 2021-02-07 00:59

i m using a select box of country, when user select a country then add branch link appears and user add branches under that country, but when user want to change country then al

4条回答
  •  清歌不尽
    2021-02-07 01:38

    I'm posting this reply at the risk of ridicule because I'm admittedly pretty noob at this stuff (only been learning a month or two), but I was able to handle a similar situation (changing time zones) just doing this:

    $(".timezonedropdown").change(function() {
        var newVal = $(this).val();
        if(!confirm("Are you sure?")) {
            $(this).val($(this).closest('select').attr("data-originaltimezone"));
        }
    });
    

    Then in my html I included data-originaltimezone="whatever" in the select. I had the class timezonedropdown for the select as well. Hope that helps! :)

提交回复
热议问题