Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | Form 6 | Q856 [ previous next ]

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

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?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.