You need to sign in to do that
Don't have an account?
Charles McDowell
jquery navigation
Using a standard controller I am trying to use jQuery to redirect my page. It does not work. I am new to jQuery, can someone identify the problem
<apex:page standardController="Request_Chemical__c" sidebar="false" >
<apex:includeScript value="$Resources.jQuery" />
<script >
var returnURL='/apex/Recommendation_Request_Dataview';
function redirectPage(){
$(location).attr('href' returnURL);
}
</script>
<apex:form >
<apex:pageBlock title="Chemical Exposure" >
<apex:pageBlockSection >
<apex:inputField value="{!Request_Chemical__c.Recommendation_Request__c}" /><br/>
<apex:inputField value="{!Request_Chemical__c.Chemical__c}" /><br/>
<apex:inputField value="{!Request_Chemical__c.Percentage__c}" />
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!Save}" oncomplete="redirectPage" value="Save" />
<apex:commandButton action="{!Cancel}" value="Back" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
<apex:page standardController="Request_Chemical__c" sidebar="false" >
<apex:includeScript value="$Resources.jQuery" />
<script >
var returnURL='/apex/Recommendation_Request_Dataview';
function redirectPage(){
$(location).attr('href' returnURL);
}
</script>
<apex:form >
<apex:pageBlock title="Chemical Exposure" >
<apex:pageBlockSection >
<apex:inputField value="{!Request_Chemical__c.Recommendation_Request__c}" /><br/>
<apex:inputField value="{!Request_Chemical__c.Chemical__c}" /><br/>
<apex:inputField value="{!Request_Chemical__c.Percentage__c}" />
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!Save}" oncomplete="redirectPage" value="Save" />
<apex:commandButton action="{!Cancel}" value="Back" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
- <apex:includeScript value="$Resources.jQuery" /> needs to have the Merge Field Syntax or it will not load the jQuery script properly, it needs to be: <apex:includeScript value="{! $Resources.jQuery }" />
- $(location).attr('href' returnURL); is missing the comma, it needs to be: $(location).attr('href', returnURL);
- You can also should also try and use the $Page merge field syntax, it makes your redirect more secure and will automatically recognise if you are in Classic, Lightning, or even SF1 Mobile and should always redirect correctly, to do that update this to: $(location).attr('href', '{! $Page.Recommendation_Request_Dataview }');
You should be good to go then! :)<apex:page >
<apex:includeScript value="{! $Resource.jQuery }"/>
<script >
var returnURL='/apex/Recommendation_Request_Dataview';
function redirectPage(){
$(location).attr('href', '{$Page.Recommendation_Request_Dataview}');
}
</script>
<apex:form>
<apex:commandButton value="Move" onclick="redirectPage" />
</apex:form>
</apex:page>