0

私はRAMのはいといいえのチェックボックスを備えた単純なフォームを作成しました。はいを押すとアラートボックスで5と表示され、いいえを押すと0と表示されますが、現在送信を押すと表示されます[オブジェクト htmlDivElement] をアラートボックスに追加します。

<script>

 function alertprice() {            // this will be called on submit of the form
 alert (runningtotal);           // alert the value in variable running total
 }


function totalprice () {                    // function totalprice will set runningtotal depending on boxes ticked
    if(document.getElementById('ramyes').checked) {
        var runningtotal = "5"
            return runningtotal;
}else if(document.getElementById('ramno').checked) {
        var runningtotal = "0"
            return runningtotal;
}
}
          </script>

そしてhtml

<form name="theForm" action="shop.html" method="post" onSubmit="checkWholeForm(theForm); return alertprice()">
                <h2>Upgrade RAM to "4GB-Kit GEIL Evo One PC3-12800 DDR3-1600 CL9"?</h2>

        <h3>
            <input type="radio" name="ram" value="yes" id="ramyes">yes<br>
            <input type="radio" name="ram" value="no" id="ramno">no     
        </h3>
4

1 に答える 1

2

関数totalprice()を呼び出す必要があります。たとえば、次のようになります。

function alertprice(){
    alert(totalprice());
}
于 2013-01-01T17:21:04.567 に答える