+ Start a Discussion
Kevin Jackson 11Kevin Jackson 11 

Trouble getting value from Selected List

Hi I am trying to get that value from a selected list as a variable going to the next VF page.  However, it continues to only give me the default value (2):

VF Page
<apex:page controller="ParameterController">
    <h1>Your latest Membership Status</h1>
  
              <apex:pageBlock >
        <apex:pageBlockSection > 
            <apex:form >       
          <p> How Long to extend your ISN membership
          
  <apex:selectList size="1" value="{!SelectedValue}" label="SelectedValue" id="SelectedValue">
        <b>  <apex:selectOptions value="{!dynamiclist}" /></b>
       <p></p>
             <apex:actionSupport event="onchange" reRender="one"  />
</apex:selectList></p><p></p>
             </apex:form>            
              <form id="browserpost" method="POST" action="Page2">
        <input type="hidden" name="namex" value="{!Contact.Name}"/>
        <input type="hidden" name="Payment" value="{!SelectedValue*203}"/> 
        <button type="submit" >
           Make Payment
        </button> 
        <apex:outputLabel id="one" >      You have selected: {!selectedValue} years.       
   The total cost will be: ${!selectedValue*203}   </apex:outputLabel>
    </form><p></p>    
              </apex:pageBlockSection>
    </apex:pageBlock> 
</apex:page>
Relevant Contoller:
 
// DROP DOWN LIST FOR YEARS TO RENEW 
    public Integer selectedValue {
    get
    {
       if(selectedValue==null)
           selectedValue=2;
 return selectedValue;   }
set;        
}

 public List<SelectOption> getdynamiclist() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('1','1 year'));
        options.add(new SelectOption('2','2 years'));
        options.add(new SelectOption('3','3 years'));
         options.add(new SelectOption('4','4 years'));
        options.add(new SelectOption('5','5 years'));
        return options;
    
    }

Any help would be appreciated!


 
Best Answer chosen by Kevin Jackson 11
Andries.NeyensAndries.Neyens
<apex:actionSupport event="onchange" action="gotoPage2"  />


    public PageReference gotoPage2() {
        return Page.Page2
    }

All Answers

ManojjenaManojjena
HI Kelvin ,

Please check below code .Why three forms functionality here in the page .
 
<apex:page controller="ParameterController">
    <h1>Your latest Membership Status</h1>
	<apex:pageBlock >
		<apex:pageBlockSection > 
			<apex:form >       
				<p> How Long to extend your ISN membership
                <apex:selectList size="1" value="{!SelectedValue}" label="SelectedValue" id="SelectedValue">
				   <b><apex:selectOptions value="{!dynamiclist}" /></b>
				   <p></p>
				    <apex:actionSupport event="onchange" reRender="one"  />
				</apex:selectList></p><p></p>
		    </apex:form>            
			<form id="browserpost" method="POST" action="Page2">
				<apex:outputLabel id="one" > You have selected: {!selectedValue} years.       
				The total cost will be: ${!selectedValue*203}   </apex:outputLabel>
			</form><p></p>    
	 </apex:pageBlockSection>
	</apex:pageBlock> 
</apex:page>

public class ParameterController{
public Integer selectedValue {
    get{
       if(selectedValue==null)
           selectedValue=2;
       return selectedValue;   }
       set;        
     }
   public List<SelectOption> getdynamiclist() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('1','1 year'));
        options.add(new SelectOption('2','2 years'));
        options.add(new SelectOption('3','3 years'));
         options.add(new SelectOption('4','4 years'));
        options.add(new SelectOption('5','5 years'));
        return options;
    
    }
}

Let me know if it helps .
Thanks 
Manoj
Andries.NeyensAndries.Neyens
take a look at this article: http://developer.force.com/cookbook/recipe/creating-a-wizard-with-visualforce-pages

bottom line, use the same controller for both VF pages and it will work...
Kevin Jackson 11Kevin Jackson 11
Hi Thanks for your answers.  Actually I am using the same controller in both VF pages.

This part works.  It rerenders and shows the value that the user chose.
 
<apex:outputLabel id="one" >      You have selected: {!selectedValue} years.      
   The total cost will be: ${!selectedValue*203}   </apex:outputLabel>

This is the part I am having trouble with.  Specifically Payment which should be !SelctedValue (3 in my example) *203.  
 
<form id="browserpost" method="POST" action="Page2">
        <input type="hidden" name="namex" value="{!Contact.Name}"/>
        <input type="hidden" name="Payment" value="{!SelectedValue*203}"/>
        <button type="submit" >
           Make Payment
        </button>

On the destination VF page I get these variables:

{!$CurrentPage.parameters.Payment}= null
{!selectedValue} = 2    (Which is the default, but it never gives me the selected value. '3' in my test)
{!$CurrentPage.parameters.Namex} =  gives me the correct name requested.


It seems that the SelectedValue variable changes its value when it rerenders, but then reverts to the default or null.

Thanks in advance for your help.
Andries.NeyensAndries.Neyens
Why don't you include that form inside 'one' so that is also rerendered ?

Another question, why are you using this constuction to post to Page2 ?
Kevin Jackson 11Kevin Jackson 11
How should I include it?  by just changing the id to equal "one"?

My objective is to simply be able to go to page 2 and pass some variables.  Do you have a better way to do it? 
Andries.NeyensAndries.Neyens
<apex:actionSupport event="onchange" action="gotoPage2"  />


    public PageReference gotoPage2() {
        return Page.Page2
    }
This was selected as the best answer
Kevin Jackson 11Kevin Jackson 11
OK.  I now see that I was going about this the wrong way.  So when I use this method rather than posting the variables pass over correctly. 

THANKS VERY MUCH!