Monday, 20 February 2017

How to Remove / Focus from First Input Field in Visualforce Page

Problem: When a Visualforce Page loads, the first input field is always selected. This can be confusing to the users as the input field is required to be populated only in certain cases. Is there any way to remove the focus/ allow me to have some other fields in focus?

Option1 - Create hidden element inside form and then focus to the hidden element

1.1 Create hidden element inside form
<input id="hiddenElement" type="hidden" />

1.2 Add following JS code to add an window.onload event to set the focus to the hidden element
<script type="text/javascript">
window.onload = setFocus
function setFocus() {

Option2 - Override the originally defined function that uses to focus on an element
2.1 Create a JavaScript function with the same name as the setFocusOnLoad function
<script type="text/javascript">
function setFocusOnLoad() {
    //do nothing

Option3 - Remove the Autofocus for all the fields and will put the focus on any field that you want
3.1 Create a JavaScript function to remove all autofocus
    window.onload = function() {
        //For putting the Focus on particular field


No comments:

Post a Comment

Follow by Email

Back to Top

What I Can Help



Do you wanna share posts

I am always looking for writers that have something interesting to say about Salesforce. Whether you have a post in mind or would like to collaborate on one, get in touch! - Click Contact Me