Remove auto focus from first input field in sales force

This articles explains how to remove automatic focus from the first input field in sales force.

In Salesforce by default, the focus is set to the first available input field. To remove the focus from that input field you can use any of the following methods.

Method 1 to Remove focus from first input field:

Add a hidden field in your page and set the focus on this hidden field when page is loaded.


<input id="myHiddenField" type="hidden" />

<script type="text/javascript">
  window.onload = setFocus
  function setFocus() {
    document.getElementById("myHiddenField").focus();
  }
</script>

Above code sets the focus on the hidden field so that your first input field (which is visible) will not have the focus now.


Method 2 to Remove focus from first input field:

You can directly remove focus from the first input field using javaScript once the page is fully loaded.

<input id="myFirstInputField" type="text" />

<script type="text/javascript">
  window.onload = setFocus
  function setFocus() {
    document.getElementById("myFirstInputField").blur();
  }
</script>

In the above javascript code we removed focus from our first input field using blur() function.

In this way we can remove auto focus from first input field in sales force.

If you know any other ways of achieving this, please feel free to post in comment so that we will add that to the article.

For more posts on javascript visit: JavaScript


No comments:

Post a Comment