1

I have a simple VF page as attached, upon clicking on the submit button it should take the phone number to another VF page and execute a javascript button on other page.

Here is my code:

<apex:page controller="phone" >
<script type="text/javascript">
function submit() {
window.location = '/apex/FindPage';
}
</script>
    <apex:form >
           <div class='form-group'>
           Enter Phone number here:
               <input class="form-control" type="text" id="phone" placeholder="Phone" />
           </div>
        <apex:commandButton styleClass="btn btn-default" value="Submit" id="findPhone" onclick="submit()"/>    
    </apex:form>
</apex:page>

enter image description here

  • After i enter some phone number and click on submit, it should open another visualforce page. After opening this phone number should be populated on the VF page..that is the expected behaviour.. – venky Mar 22 '17 at 10:15
  • And what's the problem? – Raul Mar 22 '17 at 10:15
  • on clicking the submit button, no action is being performed. it just refreshes the page. – venky Mar 22 '17 at 10:16
1

It depends on how you want to do the redirection.

1.If you want to directly link to the other page, there is the Visualforce $Page global variable.

2.If you want to send data back to the server, or otherwise perform some server based action before performing the redirect, you would want that method in your controller to return a PageReference.

In your case, since it sounds like you are building a wizard, you would want to go with method 2. On your visualforce page, your command button will call a method on the controller to pass back the current state of the page with the input values,

<apex:commandButton action="{!goToFindPage}" value="Submit" />

then the called method in the controller will return a page reference to perform the redirect.

public PageReference goToPageTwo(){
    ⋮
    return new PageReference('/apex/FindPage');
}
  • Understood, but the problem is that no action is being performed on clicking submit button – venky Mar 22 '17 at 10:24
0

Three things, 1) window.location will not render another page. It is used to set the URL of your current page. Use window.open instead.

window.open('/apex/FindPage?test@sf.com');

2) Rename the submit function to something else like submitVF may be

<apex:page >
<script type="text/javascript">
function submitVF() {
window.open('/apex/FindPage?test@sf.com');
}
</script>
    <apex:form >
           <div class='form-group'>
           Enter Phone number here:
               <input class="form-control" type="text" id="phone" placeholder="Phone" />
           </div>
        <apex:commandButton styleClass="btn btn-default" value="Submit" id="findPhone" onclick="submitVF()"/>    
    </apex:form>
</apex:page>

3) Pass the query parameter in your URL as shown above and access it from the next page using following code:

<apex:page >
 <script>
 var myEmailAdd = window.location.search;
 alert('----------------------'+myEmailAdd)
 </script>
</apex:page>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.