Hi there,
I need a way to sum all selected <option> values from within a form. My form could have up to 100 <selects> all with a name of "Frequencynnnn" nnnn being an ID number.
I have tried to modify this script I found:
function getFields() { var inputs = document.getElementsByTagName('option'), result = 0; for( var i = 0; i < inputs.length; i++ ) { var num = parseFloat( inputs.value ); //if it's a valid number add it if( !isNaN( num ) ) result += num; } alert( result ); }
However all this will do is sum all values from all options/drop downs - what I need is just the selected values added together.
Can anyone help?
Thanks
I need a way to sum all selected <option> values from within a form. My form could have up to 100 <selects> all with a name of "Frequencynnnn" nnnn being an ID number.
I have tried to modify this script I found:
function getFields() { var inputs = document.getElementsByTagName('option'), result = 0; for( var i = 0; i < inputs.length; i++ ) { var num = parseFloat( inputs.value ); //if it's a valid number add it if( !isNaN( num ) ) result += num; } alert( result ); }
However all this will do is sum all values from all options/drop downs - what I need is just the selected values added together.
Can anyone help?
Thanks