FYI, I have already posted this question on the parent site: stackoverflow.com

Here it is: How to Stop redirecting to the Parent URL from a div's Id

As this is basically a Visualforce related question, I am trying to see if anyone have encountered this kind of situation and had a solution.

I have a Visualforce page which is hosted publicly using Salesforce's Custom Urls. I have three different views (using div tag's Ids) with input forms.

One of the input forms:

<div class="container" id="leadForm1" ng-show="index == 1" >
  <apex:inputField id="compName" value="{!newPerson.SuppliedCompany}" required="true" 
                 label="Company" html-class="form-control form-control-max"/> 
  <apex:commandLink action="{!Applicant}" value="Submit" id="submitForm" onclick="doValidation();"/>


function doValidation(){
        var samTemp = document.getElementById('{!$Component.vfPage.applicantForm.theEventBlock.compName}');
        if(document.getElementById('{!$Component.vfPage.applicantForm.theEventBlock.compName}') == 'null'){
            if(alert('Please fill out all fields!')){
                window.location.href = '/InputForm#leadForm1';    

With the alert, I get an Ok button, and clicking on it taking me to the actual page(without sticking to the view, i.e., #leadForm1).

How can I make it not to redirect?

NOTE: I am trying to keep the user on the Input form until they provide some inputs to the required fields, as I am using toggle functionality within the actual Visualforce page to hide/show the input forms using:

if (x.style.display === 'none') {
            x.style.display = 'block';
        } else {
            x.style.display = 'none';
  • 2
    You should at least include the relevant information here. It's generally not nice to force people to go to another site just to see the question unless it's something complicated enough that it needs to be there.
    – sfdcfox
    Jun 12, 2018 at 18:30
  • Oh thanks @sfdcfox I thought to do it, but again felt it will be redundancy. Jun 12, 2018 at 18:32

1 Answer 1


Use the "anchor notation":

window.location.href = '#leadForm1';

This should work without redirecting/reloading the page.

  • It is still redirecting me to the actual vf page. Jun 12, 2018 at 18:41
  • @AustinEvans I don't see why it should. Perhaps you're not explaining yourself clearly enough?
    – sfdcfox
    Jun 12, 2018 at 19:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .