Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q856 How can I add up the values in several text fields and place the result in another text field?

You are here: irt.org | FAQ | JavaScript | Form | 6 | Q856 [ previous next ]

Try:

<script language="JavaScript"><!--
function calculate(what) {
    for (var i=1,answer=0;i<9;i++)
        answer += what.elements['textField' + i].value - 0;
    what.answer.value = answer;
}
//--></script>

<form>
<input type="text" name="textField1"><br>
<input type="text" name="textField2"><br>
<input type="text" name="textField3"><br>
<input type="text" name="textField4"><br>
<input type="text" name="textField5"><br>
<input type="text" name="textField6"><br>
<input type="text" name="textField7"><br>
<input type="text" name="textField8"><br>
<input type="text" name="answer">
<input type="button" value="Calcuate" onClick="calculate(this.form)">
</form>

Feedback on 'Q856 How can I add up the values in several text fields and place the result in another text field?'

©2018 Martin Webb