function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
cignuscignus 

Fill standard field automatically

Hi 

 

I am creating a VF page for contacts. When I put the <apex:inputField value="{!ownerId}" on the page it shows and empty input field, but the same thing on the standard layout is filled with current user.

How can I imitate the standard form's behavior with minimum changes in data model?

 

Cheers

Best Answer chosen by Admin (Salesforce Developers) 
Starz26Starz26

You can do it by adding this javascript to the page: The j_id0: stuff is the id of the element in my example

 

<script>

window.onload = function ()
{
document.getElementById("j_id0:mainForm:Year").value = "SOMEVALUE OR {!xxxx}";
}

</script>

All Answers

Starz26Starz26

You can do it by adding this javascript to the page: The j_id0: stuff is the id of the element in my example

 

<script>

window.onload = function ()
{
document.getElementById("j_id0:mainForm:Year").value = "SOMEVALUE OR {!xxxx}";
}

</script>

This was selected as the best answer
cignuscignus

Is it really how SF does it?

I mean this is something that should be done in business layer. It is a little awkard to pull it up to presentation.

Starz26Starz26

When you choose to go with Visualforce you have to create ALL functionality yourself.

 

And yes, when SF serves up the standard page, it populates the DOM elements by ID as well