Da Woon Jung Da Woon Jung - 10 months ago 60
jQuery Question

javascript jquery chosen not working

<!DOCTYPE html>
<meta charset="UTF-8">
<h1 id="hey">List King</h1>
<div class="Select-DB">
<select id="DB" class="chosen-select" title="Select Database" data-placeholder="Select database you want!" style="width: 300px;">
<option value=""></option>
<option value="Pubchem3D"> Pubchem3D</option>
<option value="molport"> Molport</option>
<option value="ChemAxon"> ChemAxon</option>
<option value="ChemSpider"> ChemSpider</option>
<script src="jquery-1.12.4.js" type="text/javascript"></script>
<script src="chosen_v1.6.2/chosen.jquery.js" type="text/javascript"></script>
<script src="ff.js" type="text/javascript"></script>

not working, what's wrong in my code?
My select tag just appear as default form....

p.s. Jquery code is located in another file ("ff.js")

$(".chosen-select").chosen({no_results_text: "Sorry, We don't have such database ;-)"});


Answer Source

You need to change your javascript file like this

    var aaa = $("#DB").val(); // get option value
    if(aaa === '') {
      // user select empty item
      console.log("Sorry, We don't have such database ;-)");
      // user select valid item