-1

フォームの構築について学習しようとしています。どのラジオボタンが選択されているかに基づいて、特定の変数の値を特定のフォームフィールドに割り当てたいフォームがあります。しかし、私のコードは、どちらを選択しても、常に最初のラジオの選択肢にデフォルト設定されています。

「if」条件、if/else 条件を連鎖させ、変数名を変更しようとしましたが、違いはありません。

コードが JSfiddle ( http://jsfiddle.net/GEZPU/1/ ) で機能しないこともわかりましたが、関数が定義されていないと言う理由がわかりません。

HTML

    Input 1
<select id="box0">
    <option>Tampa</option>
    <option>Phoenix</option>
</select>
<br>
<br>Input 2
<select id="box1">
    <option>Bucs</option>
    <option>Cards</option>
</select>
<br>
<br>If option radios
<br>
<br>
<input type="radio" id="box2" name="football" value="No Data">No Data
<br>
<br>
<input type="radio" id="box3" name="football" value="No Playoffs">No Playoffs
<br>Games to go?
<input id="box4" size="10">Superbowl location?
<input id="box5" size="10">
<br>
<br>
<input type="radio" id="box6" name="football" value="Yes Playoffs">Made Playoffs
<br>Superbowl location?
<input id="box7" size="10">
<p>
    <input value="Write summary" onclick="writetext()" type="button">
    <br>
    <form>
        <textarea rows="35" cols="45" placeholder="Template" id="output"></textarea>
    </form>
    <br>
</p>

コード

    function writetext() {
    var mytext = document.getElementById('output');
    var captext = "";
    // Checklist variables
    var box_0 = $("#box0").val();
    var box_1 = $("#box1").val();
    captext += box_0 + "\n - " + box_1 + "\n ";

    if ($('#box2').prop("checked ", true)) {
        var box_margin = $("#box2").val();
        captext += "\nMargins: \n - " + box_margin + "\n ";
    }
    if ($('#box3').prop("checked ", true)) {
        var box_margin2 = $("#box3").val();
        var box_margin_dist = $("#box4").val();
        var box_margin_site = $("#box5").val();
        captext += "\nMargins: \n - " + box_margin2 + "\n - Dist: " + box_margin_dist + "\n - margin " + box_margin_site + "\n ";
    }
    if ($('#box6').prop("checked ", true)) {
        var box_margin3 = $("#box6 ").val();
        var box_margin_site3 = $("#box7 ").val();
        captext += "\nMargins: \n - " + box_margin3 + "\n - (Specify margin)" + box_margin_site3 + "\n ";
    }

    mytext.value = captext;
}
4

2 に答える 2