Javascript with Visualforce pages

Javascript is one of key browser technology on Visualforce pages. Javascript provides the framework for communication between other Javascript objects, HTML elements and visualforce controller. This example will explain how can we use javascripts in visualforce pages.

<apex:page>

<script>
function changeFont(input, textid) {
if(input.checked) document.getElementById(textid).style.fontWeight = "bold";
else document.getElementById(textid).style.fontWeight = "normal";
}
</script>


<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>

<apex:outputPanel id="thePanel" layout="block">Change me!
</apex:outputPanel>
</apex:page>

'{!$Component.idName}' : This is the way of passing particular visualforce component id into the javascript.


Comments

Post a Comment

Popular posts from this blog

Displaying pop-up summaries on hover in visualforce

Do you want to be certified as a Salesforce Admin?

Unit Testing in Salesforce