A
A
Andrey Angelovich Stock2018-03-27 09:22:49
JavaScript
Andrey Angelovich Stock, 2018-03-27 09:22:49

Selecting the value of only one select'a?

Hey! There are two selects in the form. When one appears, the second disappears. The user can only select the value of one select. Then, using ajax, the values ​​are passed to the PHP handler. But the problem is that the value of the last select is always passed. How to fix it?

$('.reg').hide();
    $('#yandexUA').change(function () {
        $('#ua').toggle();
        $('#ua [value="187"]').attr('selected', 'true');
        $('#ru [value="225"]').attr('selected', 'false');


        $('#ru').hide();
    });
    $('#yandexRU').change(function () {
        $('#ru').toggle();
        $('#ru [value="225"]').attr('selected', 'true');
        $('#ua [value="187"]').attr('selected', 'false');

        $('#ua').hide();
    })

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey Angelovich Stock, 2018-03-27
@your_uncle

Thanks everyone. I did this - I remove the name and everything works)

A
Arman, 2018-03-27
@Arik

Dates different ID? You can't use the same id on multiple elements on a page.

E
Evgeny Kalibrov, 2018-03-27
@rework

here you need a code that generates data for an AJAX request to the server. I suspect that your name attribute is the same for selects. Please also note that the visibility of the form element on the page does not affect whether data is sent from it to the server or not, the data will be sent even if the element is hidden.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question