Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

83
Views
Get data-value from niceSelect to display hidden div

I have a problem after I used the niceSelect. Before this I just use simple Javascript to show and hide table. Before I used the niceSelect it works fine because the value is just value. But after I used niceSelect the value element inside the select option become data-value

HTML:

<select class="wide" id="selectTbl">
       <option value="0" selected>Select</option>
       <option value="1">Admin</option>
       <option value="2">Mechanic</option>
       <option value="3">User</option>
       <option value="4">Business</option>
</select>

Javascript:

document.getElementById('selectTbl').addEventListener('change', function () {
    $("#selectTbl").val();
    var style = $(this).val() == 1 ? 'block' : 'none';
    document.getElementById('TblAdmin').style.display = style;

    var style = $(this).val() == 2 ? 'block' : 'none';
    document.getElementById('TblMech').style.display = style;

    var style = $(this).val() == 3 ? 'block' : 'none';
    document.getElementById('TblUser').style.display = style;

    var style = $(this).val() == 4 ? 'block' : 'none';
    document.getElementById('TblBiz').style.display = style;
});

Can someone help for me? Here I want to display the div which is TblAdmin, TblMech, TblUser, TblBiz. I'm currently using NiceSelect but inside the select dropdown it has data value attribute. It actually not select but list-item inside unordered-list.

Like picture shown here, https://drive.google.com/file/d/1VyHDMb1Gl4PYBe19XZt1Z8Z-2OLAS1mx/view?usp=sharing

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Ok, I see the issue. "change" doesn't work because it's no longer a normal 'select'. You have to detect clicks and then check the value.

But I suggest you don't use this library, it seems abandoned and it's very limited, not enough methods. Also jquery is not very used nowdays.

But if you want to use the library you could do something like:

    $(document).on('click.nice_select', '.nice-select .option:not(.disabled)', function() {
      let val = $("#selectTbl").val()

      var style = val == 1 ? 'block' : 'none';
      document.getElementById('TblAdmin').style.display = style;
  
      var style = val == 2 ? 'block' : 'none';
      document.getElementById('TblMech').style.display = style;
  
      var style = val == 3 ? 'block' : 'none';
      document.getElementById('TblUser').style.display = style;
  
      var style = val == 4 ? 'block' : 'none';
      document.getElementById('TblBiz').style.display = style;
    })
about 4 years ago · Juan Pablo Isaza Report

0

// NiceSelect plugin
      $(document).ready(function(){
 
        $('#selectTbl').niceSelect();


      });

   document.getElementById('selectTbl').addEventListener('change', function () {
    $("#selectTbl").val();
    var style = $(this).val() == 1 ? 'block' : 'none';
    document.getElementById('TblAdmin').style.display = style;

    var style = $(this).val() == 2 ? 'block' : 'none';
    document.getElementById('TblMech').style.display = style;

    var style = $(this).val() == 3 ? 'block' : 'none';
    document.getElementById('TblUser').style.display = style;

    var style = $(this).val() == 4 ? 'block' : 'none';
    document.getElementById('TblBiz').style.display = style;
});

Is this correct? @madprops

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!