View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Javascript to sum drop down values

Thread began 5/17/2009 10:12 am by rdubill357341 | Last modified 5/20/2009 10:27 am by rdubill357341 | 13499 views | 5 replies

rdubill357341

Javascript Sum Drop Down Values

Ray - I have downloaded a simple javascript that adds up the values for multiple checkboxes on a page if the visitor checks the boxes - this works fine - and it displays the total on the same page...

Here is the function, script and HTML:

<script type="text/javascript" src="autoSumCheckboxes.js"></script>
function UpdateCost() {
var sum = 0;
var gn, elem;
for (i=0; i<29; i++) {
gn = 'prod'+i;
elem = document.getElementById(gn);
if (elem.checked == true) { sum += Number(elem.value) }
}
document.getElementById('totalcost').value = sum.toFixed(2);
}

<td><input type="checkbox" id='prod1' value="425.00" onclick="UpdateCost()" />
$ 425.00</td>
</tr>
<tr>
<td>T-5208-34M or L</td>
<td colspan="2">Helmet Impact Liner, medium or large</td>
<td><input type="checkbox" id='prod2' value="245.00" onclick="UpdateCost()" />
$ 245.00</td>



I now need to set up a drop down (select list) that will do the same for the values in the select list..


This does not work and the total field is blank:

<td width="169"><form id="form1" name="form1" method="post" action="">
<label>
<select name="joe" id="prod0" onchange="MM_callJS('UpdateCost()')">
<option>select</option>
<option value="100.00">one</option>
<option value="200.00">two</option>
</select>
</label>
</form></td>

I'm sure the function and select list has to change but I've tried several times - no luck...

Suggestions?

thanks in advance....

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...