Показать сообщение отдельно
  #3 (permalink)  
Старый 14.09.2019, 13:51
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,068

DivMan,
<!DOCTYPE html>

<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">
</head>

<body>
<div class="options">
        <input type="hidden" value="18" class="questionId" name="questionId">
          <input type="radio" name="r-1" id="radio-1" value="1" title=""/>
          <label for="radio-1" class="false-answer">Да</label>
          <input type="radio" name="r-1" id="radio-2" value="2" title=""/>
          <label for="radio-2" class="true-answer">Нет</label>
        </div>

<div class="options">
            <input type="hidden" value="17" class="questionId" name="questionId">
          <input type="radio" name="r-2" id="radio-3" value="1" title=""/>
          <label for="radio-3" class="false-answer">Да</label>
          <input type="radio" name="r-2" id="radio-4" value="2" title=""/>
          <label for="radio-4" class="true-answer">Нет</label>
          <input type="radio" name="r-2" id="radio-5" value="3" title=""/>
          <label for="radio-5" class="false-answer">Движение разрешено только по обочине.</label>
        </div>

<div class="options">
        <input type="hidden" value="16" class="questionId" name="questionId">
          <input type="radio" name="r-3" id="radio-6" value="1" title=""/>
          <label for="radio-6" class="false-answer">Да</label>
          <input type="radio" name="r-3" id="radio-7" value="2" title=""/>
          <label for="radio-7" class="true-answer">Нет</label>
        </div>
  <script>
    var ans = document.querySelectorAll('.options');
    ans.forEach(function (element, i) {
        var idQuestion = element.querySelector(".questionId").value;
        element.addEventListener('change', function (e) {
        var answer = e.target.value;
        console.log(idQuestion, answer)
         })
    })
  </script>
</body>
</html>

Последний раз редактировалось рони, 14.09.2019 в 13:57.
Ответить с цитированием