You need to sign in to do that
Don't have an account?
lakshman.matti
Javascript validation for if no check box is checked
I have a pageblock table. for every record i'm showing a check box.i want a validation that if no check box is checked i want show alert.
if user selected a check box i'm showing circle/process image for to show end user that some processing is happing. when user is not selected any checked and clicked on submit button i want to show validation using js or jquery(after this i dont want them to show circle/process image ).
my code is like below for button.
<apex:commandButton value="Add Selected" action="{!selectRecords}" id="sparebtn" reRender=">
<apex:actionSupport event="onclick" rerender="resultsBlock" status="statusSaveTrip"/>
</apex:commandButton>
public void selectRecords(){
system.debug('@@@@@@@@@'+spareBomList.size());
try
{
//selectedPartList.clear();
if(spareBomList.size()>0)
{
system.debug('@#@#@#');
for(Wrapper w: spareBomList)
{
system.debug('selected value'+w.isCheckBox);
if(w.isCheckBox)
{
for(integer q=1;q<=w.qty;q++)
{
selectedPartList.add(w);
}
}
}
}
if user selected a check box i'm showing circle/process image for to show end user that some processing is happing. when user is not selected any checked and clicked on submit button i want to show validation using js or jquery(after this i dont want them to show circle/process image ).
my code is like below for button.
<apex:commandButton value="Add Selected" action="{!selectRecords}" id="sparebtn" reRender=">
<apex:actionSupport event="onclick" rerender="resultsBlock" status="statusSaveTrip"/>
</apex:commandButton>
public void selectRecords(){
system.debug('@@@@@@@@@'+spareBomList.size());
try
{
//selectedPartList.clear();
if(spareBomList.size()>0)
{
system.debug('@#@#@#');
for(Wrapper w: spareBomList)
{
system.debug('selected value'+w.isCheckBox);
if(w.isCheckBox)
{
for(integer q=1;q<=w.qty;q++)
{
selectedPartList.add(w);
}
}
}
}
First of all, you have to import JQuery to your org as a Static Resource or use an external url to retrieve it.
Assuming that is a Static Resource you first have to declare it in your VisualForce:
http://www.salesforce.com/docs/developer/pages/Content/pages_resources.htm (http://www.salesforce.com/docs/developer/pages/Content/pages_resources.htm" target="_blank)
After that, you have to initiate JQuery and create a function that will check if there is at least one checkbox selected, otherwise it will show a message warning the user and preventing the submit:
The next step is to add to your commandButton your js function:
Finally, you will have to add the control style class ".chkSelected" to your apex:inputcheckbox or your input html checkbox:
That will do the magic. Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.