[SalesForce] Passing parameters through URLFOR() function not working in javascript

When click on activity name in my visualforce page, another visualforce page will open with parameters. Iam passing two parameters to visualforce page through URLFOR() function.

Code Snippet:

<apex:repeat value="{!activityList}" var="activity">
<div onClick="openDetail('{!activity.Id}','{!contactId}');">{!activity.name}                   </div> 
</apex:repeat>  

<script type="text/javaScript"> function
openPropertyDetail(actid,contid) {
var link =    '{!URLFOR($Page.ActivityPage,null,activityId=actid,contactId=contid])}';
window.open(link); }
</script>

Now the problem iam facing is, when i click on activity name the ActivityPage will open but not getting parameters inthe URL.

Can you please any one help on this.

Thanks,

Best Answer

The URLFOR is a Visualforce tag that is rendered ONCE the page is loaded/re-rendered (the value of the tag is resolved on the server). It allows only plain text values or apex variables. So you CAN'T pass javascript variables in it. What you can do it to reference your visualforce page using URLFOR and add parameters separately to the string:

var pageUrl = '{!URLFOR($Page.ActivityPage)}';
var parameters = '?activityId=' + actid + '&contactId=' + contid;
var link = pageUrl + parameters;
window.open(link);
Related Topic