0

フォームの入力フィールドから情報を取得し、JavaScriptを使用して計算しようとしています。動作していないようです。

HTML(default1.html)

<script type="text/javascript" src="multiplication.js" language="javascript"></script>  
<form>
    <table>
        <tr><!--Row 2-->
            <td class="tdSize7">
                <input class="input" name="name1" type="text"/>
            </td>
            <td class="tdSize7">
                <input class="input" name="source1" type="text"/>
            </td>
            <td class="tdSize8">
                <p>&#36;</p>
            </td>
            <td class="tdSize9">
                <input class="input" name="income1" type="text"/>
            </td>
            <td class="tdSize8">
                <p>X12</p>
            </td>
            <td class="tdSize8">
                <p>&#36;</p>
            </td>
            <td class="tdSize9">
                <input name="ann1" disabled="disabled"/>
            </td>
        </tr>
        <td class="tdSize9"><input class="inputSize2" name="" type="button" value="Calculate" onclick="addme(this.form)"/></td> 
    </table>
</form>

JavaScript(multiplication.js)

function addme(form) {
//Constant Variables
    const twelve = Number (12);
    const fourHun = Number (400);
    const fourHunEighty = Number (480);

//Monthly  Income 1
    var income1 = Number(frm.income1.value);
    var val = income1 * twelve;
    frm.ann1.value = val;
}

JavaScriptは結果を計算してフォームに入力しません。
これは私のコードのほんの一例です。私はこれが私の問題を解決するのを助けるのに十分にあなたに教えてくれることを願っています。

4

1 に答える 1

2

form代わりに使用するつもりでしたfrmか?それはあなたの問題の一部です

試す:

var income1 = Number(form.income1.value);
var val = income1 * twelve;
form.ann1.value = val;

または変更

function addme(form)

function addme(frm)
于 2012-12-27T20:58:15.303 に答える