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
Del_SantosDel_Santos 

Help with Javascript! Function lost after page refresh

Hi Guys,

 

Can someone help me. I have a visualforce page with a couple of fields and validations, I have a requirement that when a checkbox A is ticked, field C will be disabled and will copy the value entered on from field B. So for that, I am using below JS and  it is working quiet ok, however during the page refresh the functionality is lost. Field C will be blank and enabled.

 

Could someone please help.. :(

 

 

<script language="javascript">
            function ToggleInput(copyid,billhouseid,billaptid,insthouseid,instaptid)
            {
                var copy = document.getElementById(copyid);
                var billhouse = document.getElementById(billhouseid);
                var billapt = document.getElementById(billaptid);
                var insthouse = document.getElementById(insthouseid);
                var instapt = document.getElementById(instaptid);


              
                if(copy.checked == true)
                {
                    billhouse.disabled = true;
                    billhouse.value = insthouse.value;
                    billapt.disabled = true;
                    billapt.value = instapt.value;
                }
                else
                {
                    billhouse.disabled = false;
                    billapt.disabled = false;
                }
            }
           
               
        </script>
       

        <apex:inputText value="{!Lead.Installation_House__c}" required="true" id="insthouse"/>
        <apex:inputText value="{!Lead.Installation_Apartment__c}" required="true" id="instapt"/>
        <apex:inputCheckbox id="copy" value="{!Lead.Copy__c}" onchange="ToggleInput('{!$Component.copy}','{!$Component.billhouse}','{!$Component.billapt}','{!$Component.insthouse}','{!$Component.instapt}');"/>
        <apex:inputText id="billhouse" value="{!Lead.Billing_House__c}"/>
        <apex:inputText id="billapt" value="{!Lead.Billing_Apartment__c}"/>

 

 

Thanks,

Del

Starz26Starz26

add a return = false;

 

<script language="javascript">
            function ToggleInput(copyid,billhouseid,billaptid,insthouseid,instaptid)
            {
                var copy = document.getElementById(copyid);
                var billhouse = document.getElementById(billhouseid);
                var billapt = document.getElementById(billaptid);
                var insthouse = document.getElementById(insthouseid);
                var instapt = document.getElementById(instaptid);


              
                if(copy.checked == true)
                {
                    billhouse.disabled = true;
                    billhouse.value = insthouse.value;
                    billapt.disabled = true;
                    billapt.value = instapt.value;
                }
                else
                {
                    billhouse.disabled = false;
                    billapt.disabled = false;
                }

               return false;

            }
           
               
        </script>

Del_SantosDel_Santos

Hi Starz26 ,

 

Thanks for your reply, however it is still not working.  I intentionally leaved a mandatory field blank then i click on submit, the page prompt me to fill  up the field i missed, and then when i check, the value on my field C was removed durint the page onload.

 

Thanks,

Del