简体   繁体   中英

page reloads on changing the radio buttons

I'm working on a checkout process on a site. i wrote a piece of code to handle the steps, using java script and session storage. session storage keeps the current step. i wrote a function to stay on the same step on reloading the page.

it works fine, but there is two radio buttons on one of steps that user can choose the payment method using them. when user chooses one of them, page reloads but the function doesn't get called. :/ this is the function:

jQuery(document).ready(function() {
    if (sessionStorage.checkoutstepHolder > 0) {
        cartButtonHandler("onLoad");
    }
});

the question is, why the function gets called on reloads caused by refreshing, but not on reloads caused by choosing the radio buttons?

maybe the radio button doesn't reload the page, maybe its doing something else :/

I would use a seperate function for this, because you use it on multiple occasions.

jQuery(document).ready(function() {
    ReloadFunction();
});

function ReloadFunction() {
    if (sessionStorage.checkoutstepHolder > 0) {
        cartButtonHandler("onLoad");
    }
}

On radiobutton change:

jQuery(document).on('change', '#radiobuttonID', function(){
    ReloadFunction();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM