<apex:page standardcontroller="Price_Study__c" extensions="dynamicpicklist" sidebar="false" >
<apex:includeScript value="{!URLFOR($Resource.JqueryA, 'js/jquery-1.6.2.min.js')}" />
<apex:includeScript value="{!URLFOR($Resource.JqueryA, 'js/jquery-ui-1.8.16.custom.min.js')}" />
<apex:stylesheet value="{!URLFOR($Resource.JqueryA, 'css/ui-lightness/jquery-ui-1.8.16.custom.css')}" />
<apex:form id="form1">
<apex:sectionHeader title="Dynamic Picklist" subtitle="Reusable code"/>
<apex:pageblock id="saveblock">
<apex:pageBlockSection title="Dynamic picklist" columns="1" id="pbsectn">
      <apex:pageblocksectionItem id="pbs1">
          <apex:outputlabel value="City" for="values" />
          <apex:selectList value="{!city}" size="1" id="values" >
            <apex:actionSupport event="onchange" onsubmit="callControllerMethod(this.options[this.selectedIndex].text)" reRender="newvalue"  />
              <apex:selectOptions value="{!citynames}" id="citynames"/>

       <apex:inputField value="{!Price_Study__c.P3_Comments__c}" id="P1comment" style="width:200px;position:relative;height:15px;"/>                                  
          <apex:outputpanel id="newvalue">     
             <apex:outputpanel rendered="{!city == '--Other--'}">
             <div style="position:relative;left:75px;">             
                  <apex:outputlabel value="New value" for="newval" />
                  <apex:inputText value="{!newpicklistvalue}" id="newval"/>

                  <apex:commandbutton action="{!saverec}" value="Add!" />
                  <apex:commandbutton action="{!save}" value="save"/>
          <apex:commandbutton action="{!save}" value="save"/>          
function callControllerMethod(text) {


I tried with this command:


If I select others in picklist it should take that value and equate to p1 comments box

I have one pick list.When I select the value (Except option "--Others--")It will copy that value to p1 comments box using javascript which is working good.

When I select picklist value as "--Others--".It will open me new input box to add a new value. I want to copy that value to p1 comments box which is not working.

Which I click on add it should vale to p1 comment's box.

(OR)Whenever I enter a new value in the text box it should copy value to p1 comments box.

I Explained clearly about my issue.Let me know if you need more details.

Thanks in advance.


Instead of adding another input field in your UI, you can use JavaScript prompt function to collect the user input and add it in the p1 comment's box.

A recursive function can be used to force the user to provide input when other is selected. Check this jsFiddle link for a working demo.

Source code

<!DOCTYPE html>

<h2>JavaScript Prompt</h2>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

var otherval;
var txt;
function myFunction() {
    document.getElementById("demo").innerHTML = getOtherVal()+"";
  function getOtherVal(){
    otherval = prompt("Please enter other Value:", "");
    if (otherval == null || otherval == "") {
    } else {
      txt = otherval;
    return txt;

  • Hi I am adding that value to my dynamic picklist – Karthika Ram May 29 '17 at 15:30

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.