• bmontgom
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

Suppose I have a select list as shown in this visualforce code:

 

<apex:selectList id="type" size="1" value="{!type}" onchange="{!test}"> <apex:selectOption itemLabel="Type1" itemValue="Type1" /> <apex:selectOption itemLabel="Type2" itemValue="Type2" /> <apex:selectOption itemLabel="Type3" itemValue="Type3" /> </apex:selectList>

 

 and I want to alert the value of the selected selectOption from the selectList as shown in this apex code:

 

public string selectedType; public string getType() { return selectedType; } public void setType(string value) { selectedType = value; } public string getTest() { return 'alert("'+selectedType+'");'; }

 

 Now, I'm guessing the default getter and setter of the type value of the selectList does not work as I thought it would since this apex code simply alerts "null".

Does anyone know how to make this work or how to get the value of the selected selectOption within the selectList?