Nick Calladine <n i c k c a l l a d i n e @ n t lw orl d . c o m (remove all spaces)> wrote in message
news:5q******** ***********@new sfe2-win.ntli.net...
Hi
On my form i have multiple select which all have an id value total1, total2,
total3 etc so i am trying to detect how many there are and then use this to
caculate a total.
I don't think that's quite what you meant. I assume that you want to detect which elements of your form are select
boxes, in order then to read and operate on their values.
To calculate any sort of total, the values first must be converted (and convertible) in some way to numeric values.
The following function returns an array of all the selected values of all selection boxes (of either type) in a named
form.
If none of the selection boxes are set to multiple, the length of the returned array will reflect the number of
selection boxes in the form (for whatever use that may be).
function getAllSelectVal ues( formName )
{
var allSelected=[];
with( formName )
for( var i=0; i<elements.leng th; i++ )
if( elements[ i ].type=='select-one' )
allSelected[ allSelected.len gth ]=elements[i].options[ elements[i].selectedIndex ].value;
else
if( elements[ i ].type=='select-multiple' )
for( var j=0; j<elements[ i ].options.length ; j++ )
if( elements[ i ].options[ j ].selected )
allSelected[ allSelected.len gth ]=elements[ i ].options[ j ].value;
return allSelected;
}
--
Stephen Chalmers
547265617375726 520627572696564 206174204F2E532 E207265663A2054 51323437393134