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

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?

You are here: irt.org | FAQ | JavaScript | Number | Q960 [ previous next ]

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

©2018 Martin Webb