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

Q960 How can I create a form with monetary values that when selected from a drop down box the correct values are added together to give a final figure?

irt.org | Knowledge Base | JavaScript | Number | Q960 [ previous next ]

Q960 How can I create a form with monetary values that when selected from a drop down box the correct values are added together to give a final figure?

Try:

<script language="JavaScript"><!--
function update(form) {
    var total = 0;
    for (var i=0;i<form.money.length;i++) {
        if (form.money.options[i].selected) {
            total += form.money.options[i].value - 0;
        }
    }
    form.total.value = '$' + cent(total);
}
//--></script>

<form>

<select name="money" multiple size="3">
<option value="9.99">Book
<option value="29.99">Album
<option value="199.99">Bookcase
<option value="888.88">Computer
</select>

<p>Total: <input type="text" name="total"size="8">
<p><input type="button" onClick="update(this.form)" value="Click Me">

</form>

Feedback on 'Q960 How can I create a form with monetary values that when selected from a drop down box the correct values are added together to give a final figure?'


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.