• bornvirgo
  • NEWBIE
  • 0 Points
  • Member since 2010

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

Folk,

 

I am having one dropdown on Visual Force page. Onchange event i am creating new options for this select using java script. And for this select option one String varible on controller.

 

VF tag:

  <apex:selectList onchange="javascript:change()" id="myselect" size="1" value="{!testSelect}">

<apex:selectOptions value="{!picklist}"></apex:selectOptions> </apex:selectList>

 JS Funtion:

 

<script language='JavaScript'>function change(){alert('{!$Component.form.block.myselect}'); tbox = document.getElementById('{!$Component.form.block.myselect}'); clearlistbox(tbox); for(i=0; i < 5 ; i++) { var no = new Option(); no.value = 'karthi' + i; no.text = 'karthi' + i; tbox[i] = no; } } function clearlistbox(lb){ for (var i=lb.options.length-1; i>=0; i--){ lb.options[i] = null; } lb.selectedIndex = -1; }</script>

 

 

 

Controller:

 

public List<SelectOption> getPicklist(){ List<SelectOption> options = new List<SelectOption>{new SelectOption('Silambarasan','Silambarasan'),new SelectOption('Velu','Velu'),new SelectOption('Banu','Banu')}; return options; } public String testSelect {set;get;}

 

On clicking the save button i am getting the following error:

 

j_id0:form:block:myselect: Validation Error: Value is not valid

 

 Full code for VF PAge:

 

<apex:page standardController="VbApp__c" extensions="VBAPPController" ><script language='JavaScript'>function change(){alert('{!$Component.form.block.myselect}'); tbox = document.getElementById('{!$Component.form.block.myselect}'); clearlistbox(tbox); for(i=0; i < 5 ; i++) { var no = new Option(); no.value = 'karthi' + i; no.text = 'karthi' + i; tbox[i] = no; } } function clearlistbox(lb){ for (var i=lb.options.length-1; i>=0; i--){ lb.options[i] = null; } lb.selectedIndex = -1; }</script> <apex:form ID="form"> <apex:sectionHeader title="Welcom to VB Application"/> <apex:pageBlock id="block"> <apex:pageBlockButtons location="both"> <apex:commandButton action="{!save}" value="Save"/> </apex:pageBlockButtons> Name:<apex:inputText value="{!vbname}"/><br/> PickList: <apex:selectList size="1" multiselect="false"> <apex:selectOptions value="{!picklist}"></apex:selectOptions> </apex:selectList> <br/> Myselect: <apex:selectList onchange="javascript:change()" id="myselect" size="1" value="{!testSelect}"> <apex:selectOptions value="{!picklist}"></apex:selectOptions> </apex:selectList> </apex:pageBlock> </apex:form></apex:page>

 and 

 

Example for page shows

 

After changed the dromdown. I am trying to save on this time I am gettingerror "j_id0:form:block:myselect: Validation Error: Value is not valid"