Return list of value fields for checked and unchecked checkboxes

Posted By : Panaru Chaudhary | 03-Dec-2017

Let's start how to work  this method ? 

getCheckboxValues Method accept four parameter First one is form

will accept form object or form id like as :

<form id="std1"/>

here we will pass std1.

whether  var std2= jQuery("#std1");

here we will pass std2.

Second One parameter accept groupName of checkboxs fields.

Third One parameter accept true/false if you wanna to return checked checkbox value

pass true otherwise false.

Fourth parameter accept which type of value wanna return 

like as name,value,class, etc.

 

1).  Returns a list of 'value' fields for checked checkboxes.
 * Be careful: Does not add disabled checkboxes 
 * @param form form object or formId
 * @param groupName checkbox group name
 * @return a list of 'value' fields for checked checkboxes.
 * e.g.: getCheckedValues( 'dd', 'check' )

 getCheckboxValues = function( form, groupName, checkValue, type )
 {          if(typeof form !== 'object')
	{
	form = $JQ("#"+form);
	}
	var checkboxList = $JQ(form).find("input:checkbox[name='"+groupName+"']"); 
    if ( checkboxList == null ) return '';
	var list = '';

       		$JQ(checkboxList).each( function() {
                    
		if ( this.disabled  || this.checked!=checked) return;
			list += $JQ(this).attr(type) + ',';
                           
	});
	return list.substring( 0, list.length-1 );	
}
        

2.) Returns a list of 'value' fields for unchecked checkboxes.

getUnCheckboxValues = function( form, groupName, unchekValue, type )
{          if(typeof form !== 'object')
	{
	form = $JQ("#"+form);
	}
	var checkboxList = $JQ(form).find("input:checkbox[name='"+groupName+"']"); 
    if ( checkboxList == null ) return '';
	var list = '';

       		$JQ(checkboxList).each( function() {
                    
		if ( this.disabled  || this.checked!=checked) return;
			list += $JQ(this).attr(type) + ',';
                           
	});
	return list.substring( 0, list.length-1 );
	
}

About Author

Author Image
Panaru Chaudhary

Panaru is a bright Java developer with good knowledge in Core java , advance Java, Spring , Hibernate and jQuery.

Request for Proposal

Name is required

Comment is required

Sending message..