jquery - Need to clear dropdown3 on every select -


my script working fine problem append adding options in dropdown3 on every select. need clear dropdown3 every time user select option in dropdown2 tryed html insted of append html calling 1st option dropdown3 edit: have 1 more question how empty options not 1st 1 since disabled default?

<script>             $(document).ready(function() {                 var kategorije;                 $.ajax({                     url : "kategorije.txt",                     datatype: "text",                     success : function (data) {                     popunikategorije(data);                     }                 });                  function popunikategorije(kategorije){                     $.each(kategorije.split("\n").slice(0,-1), function(k, v){                         $('#dropdown2').append($('<option></option>').attr('value', k).text(v));                     });                 }              </script>          <script>         $("#dropdown2").change(function(){      var selectedvalue = $(this).find(":selected").val();          if (selectedvalue == "0")          $(document).ready(function() {                 var podkategorije;                 $.ajax({                     url : "phardware.txt",                     datatype: "text",                     success : function (data) {                     popunipodkategorije(data);                     }                 });                  function popunipodkategorije(podkategorije){                     $.each(podkategorije.split("\n").slice(0,-1), function(k, v){                         $('#dropdown3').append($('<option></option>').attr('value', k).text(v));                     });                 }             });             else if (selectedvalue == "1")          $(document).ready(function() {                 var podkategorije;                 $.ajax({                     url : "poperativnisistem.txt",                     datatype: "text",                     success : function (data) {                     popunipodkategorije(data);                     }                 });                  function popunipodkategorije(podkategorije){                     $.each(podkategorije.split("\n").slice(0,-1), function(k, v){                         $('#dropdown3').append($('<option></option>').attr('value', k).text(v));                     });                 }             });               else   if (selectedvalue == "2")          $(document).ready(function() {                 var podkategorije;                 $.ajax({                     url : "pmail.txt",                     datatype: "text",                     success : function (data) {                     popunipodkategorije(data);                     }                 });                  function popunipodkategorije(podkategorije){                     $.each(podkategorije.split("\n").slice(0,-1), function(k, v){                         $('#dropdown3').append($('<option></option>').attr('value', k).text(v));                     });                 }             });              else    if (selectedvalue == "3")          $(document).ready(function() {                 var podkategorije;                 $.ajax({                     url : "pbiaplikacija.txt",                     datatype: "text",                     success : function (data) {                     popunipodkategorije(data);                     }                 });                  function popunipodkategorije(podkategorije){                     $.each(podkategorije.split("\n").slice(0,-1), function(k, v){                         $('#dropdown3').append($('<option></option>').attr('value', k).text(v));                     });                 }             });                 else    if (selectedvalue == "4")          $(document).ready(function() {                 var podkategorije;                 $.ajax({                     url : "pkumunikacija.txt",                     datatype: "text",                     success : function (data) {                     popunipodkategorije(data);                     }                 });                  function popunipodkategorije(podkategorije){                     $.each(podkategorije.split("\n").slice(0,-1), function(k, v){                         $('#dropdown3').append($('<option></option>').attr('value', k).text(v));                     });                 }             });             else    if (selectedvalue == "5")          $(document).ready(function() {                 var podkategorije;                 $.ajax({                     url : "ppristupsistemu.txt",                     datatype: "text",                     success : function (data) {                     popunipodkategorije(data);                     }                 });                  function popunipodkategorije(podkategorije){                     $.each(podkategorije.split("\n").slice(0,-1), function(k, v){                         $('#dropdown3').append($('<option></option>').attr('value', k).text(v));                     });                 }             });             });              </script>      </html> 

try this

 $('#dropdown3').empty(); 

that remove <option> elements underneath dropdown element.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -