Add Image and label dynamically inside the dropdown

Joined
Feb 27, 2020
Messages
8
Reaction score
0
Hi ,

I have a dropdown and data is coming from VDE in JSON format. I have added values and unit in the dropdown list. But need to add icons and N/P value in the dropdown . So in the dropdown i need to add container(div/span) for adding icon and P/N value. Kindly help me
The code i am using is :
HTML:
<select id="UP_AFDuration_vals" class="PD_active_main editRPFlag Displayable Selectable ApplicableAtInitialInterrogation Applicable PreviouslyApplicable ApplicableAfterProgram" onchange="hightlightAutoManualValues(this)" style="display: inline-block;"><option value="0.5">0.5 min</option><option value="1">1 min</option><option value="2" selected="">2 min</option><option value="6">6 min</option><option value="10">10 min</option><option value="20">20 min</option><option value="30">30 min</option><option value="60">60 min</option></select>

JavaScript:
function defineUpValOpts(upValList, selectedVal) {
    
    var upOptArray = [];
    
    if (upValList !== undefined && upValList.length != 0) {
        
        for (var i = 0; i < upValList.length; i++) {
            
            var optTxt;
            var optVal;
            var upOpt;
            
            // evaluate drop-down value for special handling of "DOUBLE" value
            processParamValue(upValList[i]);
            
            if (upValList[i].unit) {
                optTxt = upValList[i].parameterValue + ' ' + upValList[i].unit;
            } else {
                optTxt = upValList[i].parameterValue;
            }
            
            optVal = upValList[i].parameterValue;
            
            if (upValList[i].parameterValue === selectedVal) {
                upOpt = new Option(optTxt, optVal, true, true);
            } else {
                upOpt = new Option(optTxt, optVal);
            }
            
            upOptArray.push(upOpt);
        }
    } else {
        console.warn('List of values, for defining a UPs Option List, was null or empty');
    }
    
    return upOptArray;
}
1646980734454.png



Thanks in advance
 
Joined
Mar 11, 2022
Messages
227
Reaction score
32
Yes you can. But not on a pure drop box (select element).

What i do actually is to hide the select element and create my own right above it. Thereyoucan add icons, spans, divs img or whatever u need.

If you just need to add something after a onchange event )your hightlightAutoManualValues), than you might do it with css and js.

Example:
Code:
<style>
.row{display:flex;}
.mSel{width:90% !important;}
.mBox{width:10% !important;}
</style>
<script>
function hightlightAutoManualValues(t){
     var imageoricon=///get_your_span_img_orwhatever_here_according_to_your_value_orsetthisto&nbsp;
     var box=document.getElementById(t.id+'_box');
    box.innerHTML=imageoricon
}
</script>
<div class="row">
<select id="UP_AFDuration_vals" class="mSel PD_active_main editRPFlag Displayable Selectable ApplicableAtInitialInterrogation Applicable PreviouslyApplicable ApplicableAfterProgram" onchange="hightlightAutoManualValues(this)" style="display: inline-block;"><option value="0.5">0.5 min</option><option value="1">1 min</option><option value="2" selected="">2 min</option><option value="6">6 min</option><option value="10">10 min</option><option value="20">20 min</option><option value="30">30 min</option><option value="60">60 min</option></select>
<div id="UP_AFDuration_vals_box" class="mBox"></div>
</div>
 
Joined
Feb 27, 2020
Messages
8
Reaction score
0
Yes you can. But not on a pure drop box (select element).

What i do actually is to hide the select element and create my own right above it. Thereyoucan add icons, spans, divs img or whatever u need.

If you just need to add something after a onchange event )your hightlightAutoManualValues), than you might do it with css and js.

Example:
Code:
<style>
.row{display:flex;}
.mSel{width:90% !important;}
.mBox{width:10% !important;}
</style>
<script>
function hightlightAutoManualValues(t){
     var imageoricon=///get_your_span_img_orwhatever_here_according_to_your_value_orsetthisto&nbsp;
     var box=document.getElementById(t.id+'_box');
    box.innerHTML=imageoricon
}
</script>
<div class="row">
<select id="UP_AFDuration_vals" class="mSel PD_active_main editRPFlag Displayable Selectable ApplicableAtInitialInterrogation Applicable PreviouslyApplicable ApplicableAfterProgram" onchange="hightlightAutoManualValues(this)" style="display: inline-block;"><option value="0.5">0.5 min</option><option value="1">1 min</option><option value="2" selected="">2 min</option><option value="6">6 min</option><option value="10">10 min</option><option value="20">20 min</option><option value="30">30 min</option><option value="60">60 min</option></select>
<div id="UP_AFDuration_vals_box" class="mBox"></div>
</div>
Thanks for the reply. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top