D
D
Delerium2016-09-08 12:34:52
JavaScript
Delerium, 2016-09-08 12:34:52

ajax check for select (.active) on previous page?

There is index.html, it selects the payment method, when you select the desired one, the .active class is assigned, each has an ID, id = "webmoney" for example) after pressing the button, there is a transition to checkout.htm where the form with inputs. I need to do that if #webmoney.active was selected on the first page, the input on the second page changed, for example, if another was selected, then another input. Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Gromov, 2016-09-08
@Delerium

If you have one link to go to checkout.htm, then in the place where you assign the active class, add:

var link = document.querySelector('селектор-ссылки');

link.href = link.href.split('?')[0] + '?active=' + active; // где active - id способа оплаты

And on the checkout.htm page:
var params = getParams();

if (params && params.active) {
    var input = document.querySelector('#' + params.active); // если у инпутов есть соответствующие id

    input.classList.add('active');
}



function getParams() {
    var query = location.search.slice(1),
        props = query.split('&'),
        result = {};

    props.forEach(function (prop) {
        if (prop) {
            var chunks = prop.split('=', 2),
                key = chunks[0],
                value = chunks[1];

            result[key] = value ? decodeURIComponent(value) : true;
        }
    });

    return Object.keys(result).length ? result : null;
}

If there are several links, then you need to go through all of them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question