V
V
Vyacheslav Mulyukin2015-11-17 15:55:35
JavaScript
Vyacheslav Mulyukin, 2015-11-17 15:55:35

How to make radio recognition in jquery?

there is such a radio that
needs to be done so that if yes then one number is variably assigned if no then another
How to recognize what is selected?

<label for="lp_ab">А/Б тестирование</label>
<label><input type="radio" name="lp_ab" id="a1" required class="lp1" />yes</label>
<label><input type="radio" name="lp_ab" id="a2" required class="lp1" checked/>no</label>
<br>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir, 2015-11-17
@Vovchikvoin

$('[name=lp_ab]:checked') // выбранный элемент

N
Nikita Borzenkov, 2015-11-17
@BashXP

$('[name="lp_ab"]').change(function () {
  if($('[name="lp_ab"]:checked').attr('id') === 'a1'){
    /// yes
  } else {
    /// no
  }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question