You need to sign in to do that
Don't have an account?

JavaScript and Repeat
I am having some issues that I need some help with.
I have a page with a field set on it that is part of a repeat tag. I want the look up field to auto populate with the users first and last name. I have found a way to populate the look up but it can't be part of the repeat tag. I am not sure what the problem is.
Visualforce code:
<apex:page standardController="Account" showHeader="false"> <script type="text/javascript" charset="utf-8" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> <script type="text/javascript" charset="utf-8" src="http://code.jquery.com/mobile/1.0b3/jquery.mobile-1.0b3.min.js"></script> <apex:form id="AccountForm"> <apex:pageBlock id="AccountBlock"> <apex:pageBlockSection id="AccountSection"> <apex:inputField id="Contact" value="{!Account.Contact_Test__c}" rendered="true"/> <apex:repeat id="FieldList" value="{!$ObjectType.Account.FieldSets.test}" var="set"> <apex:inputField id="ContactLookup" value="{!Account[set]}" rendered="{!CONTAINS(LOWER(set), LOWER('Contact_Test__c'))}"/> <apex:inputField value="{!Account[set]}" rendered="{!NOT(CONTAINS(LOWER(set), LOWER('Contact_Test__c')))}"/> </apex:repeat> </apex:pageBlockSection> </apex:pageBlock> </apex:form> <script type="text/javascript"> try { var form = document.getElementsByTagName("FORM"); var formid= '#' + form[0].id.replace(/:/g, "\\:"); $(formid+"\\:AccountBlock\\:AccountSection\\:Contact").val('{!$User.FirstName} {!$User.LastName}'); } catch(err) { alert(err); } </script> </apex:page>
Hi,
I have tried your code, use two alerts in the JavaScript. Your JavaScript executes with repeat correctly. But, you use $User.FirstName and $User.LastName which always returns the current user name.
<apex:page standardController="Account" showHeader="false">
<script type="text/javascript" charset="utf-8" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8" src="http://code.jquery.com/mobile/1.0b3/jquery.mobile-1.0b3.min.js"></script>
<apex:form id="AccountForm">
<apex:pageBlock id="AccountBlock">
<apex:pageBlockSection id="AccountSection">
<apex:inputField id="Contact" value="{!Account.Contact_Test__c}" rendered="true"/>
<apex:repeat id="FieldList" value="{!$ObjectType.Account.FieldSets.AccountsAndContactsEdit}" var="set">
<apex:inputField id="ContactLookup" value="{!Account[set]}" rendered="{!CONTAINS(LOWER(set), LOWER('Contact_Test__c'))}" />
<!-- <apex:inputField value="{!Account[set]}" rendered="{!NOT(CONTAINS(LOWER(set), LOWER('Contact_Test__c')))}" /> -->
</apex:repeat>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
<script type="text/javascript">
try
{
var form = document.getElementsByTagName("FORM");
var formid= '#' + form[0].id.replace(/:/g, "\\:");
alert(formid);
$(formid+"\\:AccountBlock\\:AccountSection\\:Contact").val('{!$User.FirstName} {!$User.LastName}');
alert($(formid+"\\:AccountBlock\\:AccountSection\\:Contact").val('{!$User.FirstName} {!$User.LastName}'));
}
catch(err)
{
alert(err);
}
</script>
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
I am having trouble using this
with the value in the repeat tag. If it is used with something outside the repeat tag it works but I need it to work with a value inside the repeat tag. I was wondering if I can use the above code with the inputfield tag that has the Id ContactLookup.