How to remove focus from Date Calendar input field …

Scenario
I had a Visualforce page where the second field is a date field. Everytime the page loads, salesforce automatically brings the date field in focus and the calendar widget pops up. This can be very confusing to the users as the date field is required to be populated only in certain cases. Is there a way to remove the focus or allow me to have some other field in focus?

Solution
Create hidden element inside form

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

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() {

document.getElementById(“hiddenElement”).focus();

}

</script>

To conclude, ..

So no longer the page load will default the focus to Calendar field and no longer the pop-up will hinder the page view.

nJoy Coding!!

Share and Enjoy:
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • LinkedIn
  • Live
  • RSS
Categories: Salesforce
Rajesh
Great … I had tried inputHidden but not the JS focus.
5 March 10 at 18:24