function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
satakshisatakshi 

javascript to check whether checkbox are checked or not

Hello,

 I am writing a code where if checkbox is checked then mail will send to desired user otherwise it will show an error "Please select checkbox". Can i get javascript for this?

<apex:pageBlockTable value="{!searchResults}" var="accWrap" id="table"">
 <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
<apex:inputCheckbox value="{!accWrap.selected}" id="inputId"/> 
<apex:column colspan="5" value="{!accWrap.acc.Name}" />
<apex:column colspan="5" value="{!accWrap.acc.Email}" />
<apex:column colspan="5" value="{!accWrap.acc.Phone}" />
</apex:pageBlockTable>
Nagendra ChinchinadaNagendra Chinchinada
satakshi,

jQuery code is easy for this.
 
<script src="https://code.jquery.com/jquery-1.11.1.min.js"> </script>
    <script> 
    j$ = jQuery.noConflict();   
    
     function validateCheckboxes(){       
            var atLeastOneIsChecked = j$('input:checkbox').is(':checked');
            if(!atLeastOneIsChecked) {
                alert('Nothig is checked ');
                return false;
                }
         return true;
    }          
        </script>

Add onClick function in button.
<apex:commandButton id="getValBtn"  value="Test" onclick="return validateCheckboxes();"  />

Instaed of unsing onclick function in button, u can use .click() in jQuer it self as explained in below article.
http://www.minerva18.com/blog/using_jquery_in_salesforce_visualforce/
satakshisatakshi
Hello C Nagendra Prasad, I have changed my code like this. now it is showing alert but after selecting checkbox its not sending mail to user