Activity Forums Salesforce® Discussions Accessing Visualforce Components values into a Javascript

  • madhulika shah

    Member
    September 13, 2018 at 1:27 pm

    Hi Anurag,

    Just add an ID to your apex:inputField and then access it in javascript using:

    var abc= document.getElementById("input_abc");

    You can then access your value using:

    abc.value

    Hope this helps.

  • shariq

    Member
    September 13, 2018 at 1:32 pm

    Hi,

    Using Component global variable, we can access visualforce components in javascript. Let us suppose, we want to use id of an apex field with id=”afield”. So, we can use the {!$Component.afield} syntax to use properties of the field in javascript.

    Thanks

  • Avnish Yadav

    Member
    September 13, 2018 at 1:54 pm

    Hello Anurag,

    I think you have to use document.getElementById('{!$Component.LabelName}') to access visualforce components values into a JavaScript.

    Thanks.

  • Parul

    Member
    September 13, 2018 at 4:59 pm

    JavaScript provides the framework for communicating between other JavaScript objects, HTML elements, and the Visualforce controller.

    JavaScript code can be written in a Visualforce page and can be included in a Visualforce page by using a static resource. This is the best method to use to include a JavaScript library in a Visualforce page. We can use the <apex:includeScript>component to include a JavaScript library from static resources.

    For example:

    <apex:includeScript value="{!$Resource.MyJSFile}"/>

     

    Thanks

Log In to reply.

Popular Salesforce Blogs