function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
John Gasior 9John Gasior 9 

Change fields on page based on picklist choice

Hi there! 

I am looking to change the fields displayed on an opportunity based on a picklist value selected. For example, if someone selects 2020, the individual months for Jan - Dec will appear for a number to be entered. 

If someone selects 2021, then the months for Jan - Dec of that year will appear for a numeric value to be entered. Is this possible? Does it require custom code? 

prachi goel 9prachi goel 9
you can make controlling picklist field
vijay kumar kvijay kumar k
Hi Jon

Your requirement needs custom code. Using custom code as per Ifprachi said u should control the picklist field of  you want further help on this plz explain your requirement with detailed example. I'm confused with numeric value to be entered.
John Gasior 9John Gasior 9
Hi Vijay,

So, it would be on the opportunity level, a controlling field named "Forecast year", with the options for 2020, 2021, 2022, 2023, 2034

If someone picked "2020", then below that there should be options for values to be entered for the custom objects

January 2020
February 2020
March 2020
April 2020
May 2020
June 2020
July 2020
August 2020
September 2020
October 2020
November 2020
December 2020

If they then picked "2021", the custom objects displayed should be 

January 2021
febraruy 2021
March 2021
etc. to December 2021.

Does that help?
vijay kumar kvijay kumar k
Hi John

Why can't you use two fields? One field contains years and another is JAN-DEC Months. If you want to display both in the same field Create a formula field and show together.

If not fine with this solution, you can achieve this requirement with the help of a custom page using javascript. So page contains two fields one is for selecting a year and another for month and year together. Use Jquery also.

For reference use below code 
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
function myFunction() {
 var x = document.getElementById("mySelect").value;

$("div").append("<select\"><option value=Janavery"+x+">Janavery"+x+"</option><option value=Feb"+x+">Feb"+x+"</option>  <option value=march"+x+">march"+x+"</option>  <option value=April"+x+">April"+x+"</option></select>");
}
</script>
</head>
<body>
<div id="Month_Year">Month Year</div>
<select onchange="myFunction()" id="mySelect">
  <option value="2019">2019</option>
  <option value="2020">2020</option>
  <option value="2021">2021</option>
  <option value="2022">2022</option>
</select>
<p id="demo"></p>
</body>
</html>