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
VINODKUMAR REDDY KALUVAVINODKUMAR REDDY KALUVA 

How to copy when data to text fields when checkbox is checked

I have a little challenge here please try:


I have a little challenge which I'm trying, I want whenever the checkbox is checked I want to copy the values into input text fields in visualforce page.
So here I have multiple rows and corresponding to that I have checkboxes, Whenever I click a checkbox values should pass to input text fields.
For more understanding, I'm attaching the screenshot of challenge.

User-added image

Please have look at the below link for the  more details :

https://salesforce.stackexchange.com/questions/260395/how-to-copy-when-data-to-text-fields-when-checkbox-is-checked
Madhukar_HeptarcMadhukar_Heptarc
Hi Vinod,

I Have understand your requirement.
By using you can JavaScript you Auto fill Input text field. I am sharing some sample code to auto fill the input text field.
 
Apex Code :
========

public class Community_Auto_Fill_Input {

    public String lastname {get;set;}
    public String Checkbox {get;set;}
    public Community_Auto_Fill_Input(ApexPages.StandardController controller) 
    {
        Contact contact = new Contact();
        lastname = 'Madhu';
    }
}   
    

VisualForce Code:
==============

<apex:page extensions="Community_Auto_Fill_Input" standardController="contact">
    <apex:form>
        <script>
        function inputDisplay(myCheck,inputId){
            if(myCheck.checked){
                document.getElementById(inputId).style.display = 'block';
            }
            else {
                document.getElementById(inputId).style.display = 'none';
            }
        }
        </script>
        <apex:pageBlock>
            <apex:pageBlockSection>
                
                <apex:pageBlockSectionItem>
                    <apex:outputLabel value="My InputCheckBox"/>
                    <apex:actionRegion>
                        <apex:inputCheckbox value="{!Checkbox}" onchange="inputDisplay(this,'{!$Component.myInputId}')"/>
                    </apex:actionRegion>
                </apex:pageBlockSectionItem>
                
                <apex:inputText id="myInputId" value="{!lastname}" style="display:none;" required="true"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
    
</apex:page>
AutoFillInputAutoFillInputinTextField

I havfe added Screenshot of above example.

Please let me kinow if it is useful (or) Any help required.

Thanks & Regards
Madhukar_Heptarc
 
VINODKUMAR REDDY KALUVAVINODKUMAR REDDY KALUVA
Hi Madhukar,

Please try to see my challenge in the below link:

I tried with javascript it's not working as well, It's not copying right row data to right text fields.

you are given simple sample code, that will not work here.
 
VINODKUMAR REDDY KALUVAVINODKUMAR REDDY KALUVA
https://salesforce.stackexchange.com/questions/260395/how-to-copy-when-data-to-text-fields-when-checkbox-is-checked