Activity Forums Salesforce® Discussions How can you access Salesforce visualforce components values into a JavaScript?

  • Prachi

    Member
    July 27, 2018 at 7:30 am

    How can you access Salesforce visualforce components values into a JavaScript?

  • Anurag algoworks

    Member
    July 27, 2018 at 10:46 am

    Hii Prachi,

    First, you need to add an ID to that particular component and then you can access it in java script by using a command - 'document.getElementById("ID"); ' .

  • Parul

    Member
    September 28, 2018 at 5:11 pm

    <apex:page id="thePage">
    <!-- A simple function for changing the font. -->
    <script>
    function changeFont(input, textid) {
    if(input.checked) {
    document.getElementById(textid).style.fontWeight = "bold";
    }
    else {
    document.getElementById(textid).style.fontWeight = "normal";
    }
    }
    </script>

    <!-- This outputPanel calls the function, passing in the
    checkbox itself, and the DOM ID of the target component. -->
    <apex:outputPanel layout="block">
    <label for="checkbox">Click this box to change text font:</label>
    <input id="checkbox" type="checkbox"
    onclick="changeFont(this,'{!$Component.thePanel}');"/>
    </apex:outputPanel>

    <!-- This outputPanel is the target, and contains
    text that will be changed. -->
    <apex:outputPanel id="thePanel" layout="block">
    Change my font weight!
    </apex:outputPanel>
    </apex:page>

Viewing 1 - 3 of 3 posts

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos