and in the same pageBlock, follwing is the portion where I am trying to get this funtion work, Name of Visit Please help me to know what am I missing here, Thank you", "answerCount": 7, "upvoteCount": 0, "datePublished": "2016-09-05T13:26:10.000Z", "author": { "@type": "Person", "name": "Pratima Shrivastav", "url": "https://trailblazers.salesforce.com/profileView?u=0053A00000DgXDWQA3", "affiliation": { "@type": "Organization", "name": "Slalom" } }, "acceptedAnswer": { "@type": "Answer", "text": "Hello prati@salesforce, In addition to soni piyush's solution: Hardcode element's Id in your javascript code it is not recommended. So, a different scenario using the code above would be passing the element Id as a parameter. By doing so, you are allowing your code to be reused as many times as you want in your Visualforce page. Please, consider the code below:       Note that using the global merge field type $Component will allow you to get element's full Id. Consider reading the following dev guide: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_variables_global_component.htm Regards.  ", "upvoteCount": 1, "url": "https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007T4YFuSAN", "datePublished": "2016-09-06T03:38:14.000Z", "author": { "@type": "Person", "name": "Developer Aviva", "url": "https://trailblazers.salesforce.com/profileView?u=0053A00000EKhMEQA1", "affiliation": { "@type": "Organization", "name": "--" } } }, "suggestedAnswer": [ { "@type": "Answer", "text": "Thank you so much Piyush and Zuinglio Lopes, It was great help.", "upvoteCount": 0, "url": "https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007T4YFuSAN", "datePublished": "2016-09-06T10:54:10.000Z", "author": { "@type": "Person", "name": "Pratima Shrivastav", "url": "https://trailblazers.salesforce.com/profileView?u=0053A00000DgXDWQA3", "affiliation": { "@type": "Organization", "name": "Slalom" } } } ] } } Skip to main content
Hi,

I am trying to execute a very simple javascript code on a visualforce page but I dont know what I am missing here, Below is a portion of my code,

<apex:page controller="PageReferSiteVisit" >

    <apex:pageMessages />

    <script>

        function changeCase(){

           var x = document.getElementById("id1");

           x.value = x.value.toUpperCase();

        }

    </script>

and in the same pageBlock, follwing is the portion where I am trying to get this funtion work,

<apex:pageBlockSectionItem >

        <apex:outputLabel >Name of Visit</apex:outputLabel>

        <apex:inputtext value="{!doctor}" id="id1" onchange="changeCase()"/>

      </apex:pageBlockSectionItem>

Please help me to know what am I missing here,

Thank you
7 Antworten
  1. 6. Sept. 2016, 03:38
    Hello prati@salesforce,

    In addition to soni piyush's solution:

    Hardcode element's Id in your javascript code it is not recommended. So, a different scenario using the code above would be passing the element Id

    as a parameter. By doing so, you are allowing your code to be reused as many times as you want in your Visualforce page. Please, consider the code below:

    <apex:page standardController="Account">

    <script>

        function changeCase(elId){

            var x = document.getElementById(elId);

            x.value = x.value.toUpperCase();

        }

    </script>

    <apex:form>

        <apex:inputField value="{!account.Name}" id="id1" onchange="changeCase('{!$Component.id1}');"/>

    </apex:form> 

    </apex:page>

    Note that using the global merge field type $Component will allow you to get element's full Id. Consider reading the following dev guide:

    https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_variables_global_component.htm

    Regards.

     
0/9000