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
ram dram d 

how to add one text field value to empty text field by using custom button in lightning ?

Hi All,

how to add one text field value to empty text field by using custom button in lightning  any help much appreciate 

Thanks in Advance
Khan AnasKhan Anas (Salesforce Developers) 
Hi Ram,

Greetings to you!

Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.

Component:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" 
                access="global" >
    
    <aura:attribute name="PageHeading" type="String" default="Copy Fields Through Button" />
    <aura:attribute name="name" type="String" />
    <aura:attribute name="cname" type="String" />
    
    
    <div class="slds-m-top--xx-large">
        <div class="slds-page-header">
            <div class="slds-align--absolute-center">
                <div class="slds-text-heading--large">       
                    {!v.PageHeading}
                </div>
            </div>
        </div>
    </div>
    <br/> <br/>
    
    <div class = "slds-size--3-of-8">
        <div class="slds-section slds-is-open">
            <h3 class="slds-section__title slds-theme_shade">
                <span class="slds-truncate slds-p-horizontal_small" title="Section Title">Text Box 1</span>
            </h3>
            <br/>
            <div aria-hidden="false" class="slds-section__content">
                <lightning:input label="Enter Name" aura:id="nameId" name="name" value="{!v.name}"/>
                <br/>
                <lightning:button label="Add"
                                  variant="brand"
                                  onclick="{!c.onClickButton}"
                                  />
                <br/>
            </div>
        </div>
        <br/> 
        <div class="slds-section slds-is-open">
            <h3 class="slds-section__title slds-theme_shade">
                <span class="slds-truncate slds-p-horizontal_small" title="Section Title">Text Box 2</span>
            </h3>
            <br/>
            <div aria-hidden="false" class="slds-section__content">
                <lightning:input label="Enter Name" aura:id="cnameId" name="name" value="{!v.cname}"/>
                <br/>
            </div>
        </div>
    </div>
    
</aura:component>

Controller:
({
    onClickButton : function(component, event, helper) {
        // textbox in which you enter data
        var nameStr=component.get("v.name");
        // textbox in which you copy data
        component.set("v.cname",nameStr);
    }
})

CSS:
.THIS {
}

.THIS.slds-size--3-of-8 {
    margin-left: 480px;
}

.THIS label.slds-form-element__label{
    
    font-size: 1.00rem;
    color: blue;
}

.THIS .slds-section__title{
    background-color: #1589ee;
    color: white
}

Application:
<aura:application extends="force:slds">
    <c:ButtonCopy />
</aura:application>

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas