Dashboards & Visualizations

How to make the first available value in a 2nd drop-down be selected by default when the first drop-down selection changes?

Divya_B07
New Member

Hi All,

I have two drop-downs where the 2nd drop-down is populated based on the value selected in the 1st drop-down.
Please let me know how to make the first available value in the 2nd drop-down to be selected by default when the 1st drop-down selection changes. Currently the old selected value is retained in the 2nd drop-down when the 1st drop-down value is updated.

NOTE : This issue does not occur on page load because of selectFirstChoice, but happens on subsequent changes.

Eg : 2nd drop-down has {A,B,C} and A is selected on page load. When 1st drop-down is updated, 2nd drop down has {X,Y,Z} values, but still A is retained as the default value.

Thanks in advance!

0 Karma
1 Solution

dkeck
Influencer

Hi,

I am not sure I got the problem correctly, but

I build a test dashboard with sourcettype and depending sources.

So first Dropdown is sourcettypes with a default value. Second Dropdown contains the sources related to the selected sourcetype.

Looks like this : index=_internal sourcetype="$tok_sourcetype$" | top source

Thats what you allready got, right?

So if you also set one of the sources of the default sourcetype as default in the source dropdown. It will automatically set the first value in source as default in the dropdown, when you change the value in the first dropdown.

Also you have to activate "Search on Change".

Is that what you are looking for?

Kind Regards

View solution in original post

0 Karma

dkeck
Influencer

Hi,

I am not sure I got the problem correctly, but

I build a test dashboard with sourcettype and depending sources.

So first Dropdown is sourcettypes with a default value. Second Dropdown contains the sources related to the selected sourcetype.

Looks like this : index=_internal sourcetype="$tok_sourcetype$" | top source

Thats what you allready got, right?

So if you also set one of the sources of the default sourcetype as default in the source dropdown. It will automatically set the first value in source as default in the dropdown, when you change the value in the first dropdown.

Also you have to activate "Search on Change".

Is that what you are looking for?

Kind Regards

0 Karma

Divya_B07
New Member

The following steps fixed the issue.

  1. Addition of true to the second dropdown.
  2. Unset the second dropdown selection when the first dropdown selection changes.

Given below is the snippet:

    <label>First Dropdown:</label>
    <search>
      <query>……. </query>
    </search>
    <fieldForLabel> First Dropdown</fieldForLabel>
    <fieldForValue> First Dropdown</fieldForValue>
    <default>A</default>
     **<change>
         <unset token="form. second_dropdown "></unset>
     </change>**
  </input>
  <input type="dropdown" token="second_dropdown" searchWhenChanged="true">
    <label>Second Dropdown:</label>
    <search>
      <query>…….. </query>
    </search>
    <fieldForLabel> Second Dropdown</fieldForLabel>
    <fieldForValue> Second Dropdown</fieldForValue>
    **<selectFirstChoice>true</selectFirstChoice>**

Thanks!

0 Karma

dkeck
Influencer

If you want to test it, this could help

 <form>
  <label>test dropdown</label>
  <fieldset submitButton="false" autoRun="false">
    <input type="dropdown" token="tok_sourcetype">
      <label>field1</label>
      <search>
        <query>index=_internal| top limit=20 sourcetype</query>
      </search>
      <fieldForLabel>sourcetype</fieldForLabel>
      <fieldForValue>sourcetype</fieldForValue>
      <default>splunkd</default>
    </input>
    <input type="dropdown" token="field2" searchWhenChanged="true">
      <search>
        <query>index=_internal sourcetype="$tok_sourcetype$" | top source</query>
      </search>
      <fieldForLabel>source</fieldForLabel>
      <fieldForValue>source</fieldForValue>
      <default>/opt/splunk/var/log/splunk/metrics.log</default>
    </input>
  </fieldset>
</form>
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...