Many thanks.", "answerCount": 3, "upvoteCount": 0, "datePublished": "2021-09-07T12:11:36.000Z", "author": { "@type": "Person", "name": "Juan Antonio Cantarero", "url": "https://trailblazers.salesforce.com/profileView?u=0053A00000EeK30QAF", "affiliation": { "@type": "Organization", "name": "--" } }, "acceptedAnswer": { "@type": "Answer", "text": "Change this line to Change Script This will work definately... enjoy :)  ", "upvoteCount": 1, "url": "https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007T4PciSAF", "datePublished": "2021-09-08T18:52:09.000Z", "author": { "@type": "Person", "name": "Dushyant Sonwar", "url": "https://trailblazers.salesforce.com/profileView?u=0053000000AKdjPAAT", "affiliation": { "@type": "Organization", "name": "Accenture" } } }, "suggestedAnswer": [] } }
Skip to main content
Dear. 

This seems an easy question with easy solution, but I don't find a technical solution after look in google, developer salesforce, etc.

This is what I want: I need to perform a set of validations in a lot of custom field values of the Opportunity. After see different options (process builder, validation rules, formulas, etc) the best approach if to use a VisualForce page. In that VisualForce page I want to show a text custom field, with a custom error message that can change via visualforce/javascript code.

This is my issue: I am not able to change the text custom field value. I have no erros. Just no changes on the text value. Below is the code I used in the VisualForce page.

Do you have any suggestion?

 

<apex:page standardcontroller="Opportunity">

<apex:form id="formId">

<apex:pageblock id="pb">

<apex:pageBlockSection id="Block1" title="Opportunity Information" columns="2">

<apex:inputField id="Warning_message" value="{!Opportunity.Warning_message__c}" />

</apex:pageBlockSection>

</apex:pageblock>

</apex:form>

<script type="text/javascript">

function myFunction()

{

document.getElementById('{!Opportunity.Warning_message__c}').value = "This will not change the value";

document.getElementById('{!Opportunity.Warning_message__c}').innerHTML= "This will not change the value";

document.getElementById('Warning_message').value = "This will not change the value";

document.getElementById('Warning_message').innerHTML= "This will not change the value";

document.getElementById('{!$Component.formId.pb.Block1.Warning_message}').value = "This will not change the value";

}

var msgObj= document.getElementById('{!Opportunity.Warning_message__c}');

msgObj.value = "This will not change the value";

msgObj.innerHTML= "This will not change the value";

</script>

</apex:page>

Many thanks.

 
3 answers
  1. Sep 8, 2021, 6:52 PM

    Change this line

    <apex:inputField id="Warning_message" value="{!Opportunity.Warning_message__c}" />

    to

    <apex:inputField id="Warning_message" styleClass="warningTxtBoxCls" value="{!Opportunity.Warning_message__c}" />

    Change Script

    <script>

    window.onload = function() {

    document.getElementsByClassName('warningTxtBoxCls')[0].value = 'This is definately changing the value';

    };

    </script>

    This will work definately... enjoy :)

     
0/9000