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
nagasnagas 

multiple selection checkbox

hi,

 

I have a requirement where two sections 

 

1. it has a search input filed where the user enters a name and clicks on search which will display a list of users with check boxes and the user is allowed to select the checkboxes what user they want.

 

2. in this section it should display the users which the user selected using the checkboxes in the top section if a user deselects on the top section it should deselect in the bottom section also.

 

Can anybody explain me how it can be achieved. I know may be it can achieved using java script but not sure how to start with i may cretae a onclick function which calls the javascript and in the java script i can add all the selected users to below section. but not sure about the code i dont know javascript much. 

Pradeep_NavatarPradeep_Navatar

Find below a sample code for Your functionality. You Can Use This Java Script Code :

<SCRIPT>
<!--

<!-- Begin
function Check(chk)
{
if(document.myform.Check_ctr.checked==true){
for (i = 0; i < chk.length; i++)
chk[i].checked = true ;
}else{

for (i = 0; i < chk.length; i++)
chk[i].checked = false ;
}
}

// End -->
</script>



Here is the code for body part .

<form action="checkboxes.asp" method="post">
<b>Scripts for Web design and programming</b><br>
<input value="1">ASP<br>
<input value="2">PHP<br>
<input value="3">JavaScript<br>
<input value="4">HTML<br>
<input value="5">MySQL<br>

<input value="yes"
onClick="Check(document.myform.check_list)"><b>Check Control</b>

</form>

nagasnagas

but how can i capture the selected records using checkboxes. Thanks for the prior answer. Anyways i will post the code what i have done till now.

 

 

Page:

 

 

<apex:page standardController="Territory" extensions="assignuser" >
 <apex:sectionHeader title="Territory User Assignment" subtitle="{!Territory.Name}"/>
    <apex:form id="taForm">
        <apex:pageBlock mode="edit" title="Territory Information">
            <apex:pageBlockSection columns="1">
                <apex:outputField value="{!Territory.Name}"/>
                <apex:outputField value="{!Territory.ForecastUserId}"/>
              
            </apex:pageBlockSection>
        </apex:pageBlock>
       
            <apex:pageBlock title="User Assignemnt" >
           <apex:pageBlockSection >
           <apex:outputPanel layout="SearchBlock">
              <apex:outputLabel value="User Name"/>
              <apex:inputText id="searchtext" value="{!searchStr}" size="15"/>
              <apex:CommandButton Value="Search" action="{!submit}" />
              <br/>

              <div><b><font color='red'><apex:outputText value="{!SearchError}" rendered="{!SearchError != ''}"></apex:outputText></font></b></div>

                                       
           </apex:outputPanel>   
           
           
           </apex:pageBlockSection>
           
           <apex:pageBlockTable value="{!usersList}" var="tu" rendered="{!listFlag == 'true'}" >
                   <apex:column HeaderValue="select">
                   <apex:selectCheckboxes id="tcheckid" value="{!selectedUser}">
                     <apex:actionSupport event="onclick" action="{!GetSelected}" />
                            <apex:selectOption value="{!selectId}" itemValue="{!tu.Id}" itemLabel="{!tu.name}">
                             </apex:selectOption>
                      </apex:selectCheckboxes>
                     <!--<apex:actionSupport action="{!getselectedusers}"  event="onclick" reRender="selectedreps"/>-->
                    </apex:column>
                   
                    <apex:column value="{!tu.Territory_Code__c}"/>
                 </apex:pageBlockTable>
            </apex:pageBlock>
            
            
        <apex:outputPanel style="text-align:center">
           <!-- <apex:commandButton action="{!assignUser}" value="Assign User"  onclick=" return testSelected();"/>-->
            <apex:commandButton action="{!cancel}" value="Cancel"/>
        </apex:outputPanel>
        
        <apex:inputhidden value="{!selectuser}" id="selId"/>
   <script type="text/javascript">
            var Previd;
            function testSelected(){

                var checked ;
                checked = document.getElementById('{!$Component.selId}').value ;
                if(checked == '' ){
                        alert('Please select a User' );
                        return false;

                 }
                  return true ;
            }

   

      </script>
                     
  </apex:form>

</apex:page>

 controller

 

 

public with sharing class assignuser {

   public String searchStr{get;set;}
   public String searchError{get;set;}
   Territory terr;
   public String selectuser{get;set;}
   public String selectId{get;set;}
   public String ListFlag{get;set;}
    public List<User> usersList = null ; 
    public List<User> searchList = null ; 
    public List<User> selectedusers = new List<User>();
     public String selectedUser{get;set;}
     
     
    public assignuser(ApexPages.StandardController controller) {
   
    System.debug('Entering into Controlller'); 
        this.terr = (Territory)Controller.getRecord(); 

    }
    
    public assignuser(String UserName,String searchStr, Territory terr){
    
    this.selectuser = UserName;
    this.searchStr = searchStr;
    this.terr = terr;
    }
    
    // Gives the list of users that match the search criteria
    public List<User> getusersList()
    {
     List<User> terruserList = new List<User>();
        searchError = '' ;
        listFlag = 'true';
        if(terruserList != null){
            terruserList.clear();
        }
        
        if(searchStr!=null)
        searchStr=searchStr.trim();
        
        if(searchStr != null && searchStr.trim().length() > 0 ){

            System.debug('Search String :'+searchStr);
            
             //The following Query for Wildcard search
            if(searchStr.contains('*')){
                searchStr = searchStr.replace('*', '');
                searchStr = searchStr.trim();
            }
                //Following Code for Searching by Using UserName
                for(List<User> user :[select Id,name,Territory_Code__c from user where name like :('%'+searchStr+'%') limit 400]){
                    terruserList.addAll(user);
                }
            }
            
            if(terruserList != null && terruserList.size() == 0){
            
                searchError = 'Your search did not return a result. Please try again.';
                listFlag = 'false';
            }
    
        System.debug('Exiting getusersList:');
        return terruserList ;
        
    }
            
    // the territory information 
    public Territory getTerrirory(){
    
    if(terr==null){
    terr = new Territory();
    }
    return terr;
    }
    
     public String Submit(){
        
     searchList = getusersList();
        return Null;
    }  
 }

 

 

 

this code now can display the list of users with checkboxes. I should extend it to work for when i select a checkbox here a section below should show up and display the selected record and when i deselct the checkbow on top the record should disappear in the bottom section. 

So what i taught is if we can capture the records which we have selected in top section in  a list. we can display in the bottom section easily..

Hope i gave enough information. please let me know if you need more information.