View Single Post
Old 12-15-2012, 04:00 PM   PM User | #8
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,764
Thanks: 29
Thanked 453 Times in 447 Posts
jmrker will become famous soon enough
Thumbs up

Quote:
Originally Posted by logic ali View Post
Code:
function getGroupValue( group ) /* group == radio/checkbox single/group or <select> options list */
{
  var selectedElems = [],
      g;
  
  if( group.length === undefined )
  { 
    if( group.checked || group.selected )
      selectedElems.push( group.value );
  }
  else
    for( g = 0; group[ g ]; ++g ) 
      if( group[ g ].checked || group[ g ].selected ) 
        selectedElems.push( group[ g ].value );
  
  return selectedElems.length > 0 ? selectedElems : null; 
}
wow!!!
I like the idea of one function to collect information from different element types.
Less typing, less prone to errors, common implementation, understandable and neat all rolled-up into one small package.
Thanks for the attention to the topic, 'Logic Ali'.

Added to the "Post A JavaScript" section of this forum. See: http://www.codingforums.com/showthre...64#post1300264

Last edited by jmrker; 12-16-2012 at 02:27 PM..
jmrker is offline   Reply With Quote