Dashboards & Visualizations

How to create a dynamic drop-down based on the selection of another drop-down?

Explorer

Hi

I want to achieve this:
DROPDOWN1 will have A B
and DROPDOWN2 should be populated based on what is selected in DROPDOWN1

IF DROPDOWN1 = A then DROPDOWN2 should show 1 and 2
IF DROPDOWN1 = B then DROPDOWN2 should show 3 and 4

0 Karma

Explorer

What i am trying is something like this

<label>Select a Value:</label>
<default>A</default>
<choice value="A">A</choice>
<choice value="B">B</choice>



<label>Select a Value:</label>
Eval $DROPDOWN1$ = “A”
<choice value="A">1</choice>
<choice value="B">2</choice>
Eval $DROPDOWN1$ = “B”
<choice value="A">3</choice>
<choice value="B">4</choice>

Can you please help?

0 Karma

Motivator

Hi vinay4444
See the following xml code , i think it will help you

     <form>
    <label>Cascading dropdown</label>
    <description/>
    <fieldset submitButton="false" autoRun="true">
    <input type="dropdown" token="varSourcetype" id="field1">
    <label>SourceType :</label>
    <populatingSearch fieldForValue="sourcetype" fieldForLabel="sourcetype">
    <![CDATA[index=_internal earliest=-1h@h | top 1 sourcetype | table sourcetype ]]>
    </populatingSearch>
    </input>
    <input type="dropdown" token="varSource" id="field2">
    <label>Source :</label>
    <populatingSearch fieldForValue="source" fieldForLabel="source">
    <![CDATA[index=_internal earliest=-1h@h sourcetype=$varSourcetype$ | stats count by source ]]>
    </populatingSearch>
    </input>

    </fieldset>
    <row>
    <table>
    <title>Volume distribution- sourcetype=$varSourcetype$ source=$varSource$ </title>
    <searchString>
    <![CDATA[index=_internal earliest=-1h@h sourcetype=$varSourcetype$ source=$varSource$
  | timechart span=5m count ]]>
    </searchString>
    <option name="count">10</option>
    <option name="previewResults">true</option>
    <option name="drilldown">none</option>
    </table>
    </row>
    </form>

Note that the second dropdown varSource is populated with the first dropdown varSourcetype

0 Karma

Explorer

Thanks for response but can you please help me to get static values in secind dropdown bases on dropdown 1
i need to see 1 and 2 in dropdown 2 when i select A in drop down 1 , am i missing some thing here?

0 Karma

Motivator

can you please send me your xml code ?

0 Karma

Explorer

need correct XML for field2 so that values will be 1 and 2 when I select A for field

Cascading dropdown

<input type="dropdown" token="fieldA" searchWhenChanged="true">
  <label>Select a Value:</label>
  <default>A</default>
  <choice value="A">A</choice>
  <choice value="B">B</choice>
</input>
<input type="dropdown" token="fieldB" searchWhenChanged="false">
  <label>Select :</label>
  <prefix>filed2="</prefix>
  <suffix>"</suffix>
  <search>
    <query>index=_internal Field=$fieldA$| stats count by field2</query>
    <earliest>0</earliest>
    <latest>now</latest>
  </search>
  <fieldForLabel>filed2</fieldForLabel>
  <fieldForValue>field2</fieldForValue>
</input>
0 Karma

Motivator

use this

 <input type="dropdown" token="fieldA" searchWhenChanged="true">
       <label>Select a Value:</label>
       <default>A</default>
       <choice value="1">A</choice>
       <choice value="2">B</choice>
     </input>
     <input type="dropdown" token="fieldB" searchWhenChanged="false">
       <label>Select :</label>
       <prefix>filed2="</prefix>
       <suffix>"</suffix>
       <search>
         <query>set union[search index=_internal fieldA=$fieldA$|eval field2=fieldA|fields field2][search index=_internal fieldA=$fieldA$|stats sum(fieldA) as field2|fields field2 ]</query>
         <earliest>0</earliest>
         <latest>now</latest>
       </search>
       <fieldForLabel>filed2</fieldForLabel>
       <fieldForValue>field2</fieldForValue>
     </input>
0 Karma

Explorer

Thanks , does not work when i select A in first drop down i do not get any thing in second one . i expect values 1 and 2 there

0 Karma

Motivator

hi Vinay4444,

that is the example dropdon based on other dropdown.

<fieldset autoRun="true" submitButton="false">
    <input type="dropdown" token="fieldA" searchWhenChanged="true">
      <label>Select a Value:</label>
      <default>*</default>
      <choice value="*">All</choice>
      <choice value="A">A</choice>
      <choice value="B">B</choice>
    </input>
    <input type="dropdown" token="fieldB" searchWhenChanged="true">
      <label>Select :</label>
      <prefix>filed2="</prefix>
      <suffix>"</suffix>
      <default>*</default>
      <choice value="*">All</choice>
      <populatingSearch fieldForValue="field2" fieldForLabel="filed2" earliest="0" latest="now">
        index=_internal Field=$fieldA$| stats count by field2
      </populatingSearch>
    </input>
  </fieldset>
0 Karma

Explorer

Hi Thanks for response i can not see 1 and 2 in dropdown 2 when i select A in drop down 1 , am i missing some thing here?

0 Karma

Motivator

Are A and B values or fields?

0 Karma

Explorer
 <input type="dropdown" token="fieldA" searchWhenChanged="true">
   <label>Select a Value:</label>
   <default>*</default>
   <choice value="*">All</choice>
   <choice value="A">A</choice>
   <choice value="B">B</choice>
 </input>

This when i select A in above drop down i need to get values 1 and 2 in fieldB

0 Karma

Motivator

How is called the field that contains the values A and B?

0 Karma

Explorer

sorry dint get you?

0 Karma

Motivator

A and B are the values of any field in your index or in your data?

0 Karma

Explorer

No none of them are in data i want to just hardcode those values A and B as well as 1,2,3,4 for second dropdown.

0 Karma

Motivator

A must be a field with the values 1 and 2
B must also be a field with the values 3 and 4

if this is the case, it will work, if otherwise I have no solution

0 Karma

Motivator

you can not have a better result than if A and B are fields such as: field has values 1 and 2, while field B has the values 3 and 4.

is what is the case?

0 Karma