0

2 つの異なるグループからラジオ ボタンの値を取得する方法 (DIV: ステップ 1 とステップ 2)?? 実際には5つ持っていますが、同じ話になります。

初期化中

        var a1Id;
        var a2Id; 
        var a3Id;
        var a4Id; 
        var a5Id;
        var a6Id; 

a1Id = questionaireResult.questions[0].answers[0].id; (value of id = 1)
            document.getElementById('antwort1fuerFrage1').value = a1Id;

 a2Id = questionaireResult.questions[0].answers[1].id; (value of id = 2)
                document.getElementById('antwort2fuerFrage1').value = a2Id;

and so on for 3,4,5, and 6...

JQUERY hier 選択したラジオボタンの値を読みたいです。グループごとにやってる

var selected = $("#step-1 input[type='radio']:checked");
                if (selected.length > 0) {
                    var answerIDQ1 = $('input[class=group1]:checked').val();
                }

                var selected = $("#step-2 input[type='radio']:checked");
                if (selected.length > 0) {
                    var answerIDQ2 = $('input[class=group2]:checked').val();
                }

HTML

<div id="step-1">
                <h2 class="StepTitle">
                    <label style="font-weight: bold; color: #662819;" id="frage1"></label>
                </h2>
                <br />

                <input type="radio" class="group1" name="group1" id="frage1antwort1" value="" onmousedown="this.__chk = this.checked" onclick="if (this.__chk) this.checked = false" />
                <label id="antwort1fuerFrage1"></label>
                <br />
                <br />
                <input type="radio"  class="group1" name="group1" id="frage1antwort2" value="" onmousedown="this.__chk = this.checked" onclick="if (this.__chk) this.checked = false" />
                <label id="antwort2fuerFrage1"></label>
                <br />
                <br />
                <input type="radio"  class="group1" name="group1" id="frage1antwort3" value="" onmousedown="this.__chk = this.checked" onclick="if (this.__chk) this.checked = false" />
                <label id="antwort3fuerFrage1"></label>
            </div>

            <div id="step-2">
                <h2 class="StepTitle">
                    <label style="font-weight: bold; color: #662819;" id="frage2"></label>
                </h2>
                <br />

                <input type="radio"  class="group2" name="group2" id="frage2antwort1" value="" onmousedown="this.__chk = this.checked" onclick="if (this.__chk) this.checked = false" />
                <label id="antwort1fuerFrage2"></label>
                <br />
                <br />
                <input type="radio"  class="group2" name="group2" id="frage2antwort2" value="" onmousedown="this.__chk = this.checked" onclick="if (this.__chk) this.checked = false" />
                <label id="antwort2fuerFrage2"></label>
                <br />
                <br />
                <input type="radio"  class="group2" name="group2" id="frage2antwort3" value="" onmousedown="this.__chk = this.checked" onclick="if (this.__chk) this.checked = false" />
                <label id="antwort3fuerFrage2"></label>
            </div>
4

1 に答える 1