Spooner
Spooner

Reputation: 3

JavaScript will not calculate and input my results back into my form

Trying to pull information from my form input fields and calculate them using JavaScript. It does not seem to be working.

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;
}

My JavaScript will not calculate and input my results back into my form.
This is just a sample of my code. I am hoping this will tell you enough and help you, in helping me fixing my problem.

Upvotes: 0

Views: 371

Answers (1)

Sharlike
Sharlike

Reputation: 1789

Did you intend to use form instead of frm? That is part of your problem

Try:

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

Or change

function addme(form)

to

function addme(frm)

Upvotes: 2

Related Questions