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 );
}
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Panaru Chaudhary
Panaru is a bright Java developer with good knowledge in Core java , advance Java, Spring , Hibernate and jQuery.