Dynamic drop down list javascript / jQuery Best 2 Example

dynamic drop down list javascript : Example with demo – There are many different ways to create dynamic drop down lists in a website. We’ll show you how to create one using JavaScript. Dynamically create a drop-down list with JavaScript/jQuery Example

dynamic drop down list javascript and HTML

dynamic drop down list html Example: Car Make and Model List

<!DOCTYPE html>
<html>
<body>
<b>javascript dynamic dropdown list</b>
<select name="make" id="make" onChange="changemod(this.value);">
    <option value="" disabled selected>Select</option>
    <option value="Tamil">Tamil</option>
    <option value="Hindi">Hindi</option>
    <option value="Telugu">Telugu</option>
</select>
<select name="mtype" id="mtype">
    <option value="" disabled selected>Select</option>
</select>

<script>
var mtypesByMake = {
    Tamil: ["123movierulz", "filmyzilla", "3movierulz"],
    Hindi: ["9xmovies", "9xflix", "filmygod"],
    Telugu: ["cinemavilla", "filmymeet", "filmy4wap", "5movierulz"]
}
    function changemod(value) {
        if (value.length == 0) document.getElementById("mtype").innerHTML = "<option></option>";
        else {
            var mtypeOptions = "";
            for (mtypeId in mtypesByMake[value]) {
                mtypeOptions += "<option>" + mtypesByMake[value][mtypeId] + "</option>";
            }
            document.getElementById("mtype").innerHTML = mtypeOptions;
        }
    }
</script>
 
</body>
</html>

Also Read : Cascading Dependent Dropdown Country, State, City Using JavaScript

Read Also:  htaccess redirect https to http- How to redirect HTTP to HTTPS Using .htaccess?

Dynamically Fill HTML Dropdown Option Values using Javascript

 <!DOCTYPE html>
 <html lang="en">
 <head>
  <meta charset="UTF-8">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
  <title>How to fill drop down values using non ajax method</title>
  <script>
	var _data = {};
        var _data = {"Env":{"kmovie":"besthdmovies","movies4u":"movies4u"},"Org":{"kmovie":"besthdmovies Org","movies4u":"movies4u Org"}};
  </script>
</head>
<body>
  <div class="container">
    <h3>Filling HTML dropdown options using javascript or NON Ajax</h3>
    <div class="col-sm-4 row">
	<select class="form-control" id="movie-select">
	<option value="">-- Select --</option>
			 <option value="Env">Env</option>
			<option value="Org">Orgnisation</option>
			
	</select>
	</div>
	<div class="col-sm-4">
	<select class="form-control"  id="movie_ddl">
	<option value="">-- Select --</option>
	</select>
	</div>
  </div>
</body>
</html>
<script type="text/javascript">
  $(document).ready(function(){

    $('#movie-select').on('change', function(e){
        var source = $(this),
            val = $.trim(source.val()),
            target = $('#movie_ddl');
			$(target).empty();
        if(typeof(_data[val]) != "undefined"){
            var options = (typeof(_data[val]) != "undefined") ? _data[val] : {};
			 $('<option>-- Select --</option>').appendTo(target);
            $.each( options , function(value, index) {
                    $('<option value="' + value + '">' + index + '</option>').appendTo(target);
            });
        }

    });
  });
</script>

I hope you get an idea about dynamic drop down list javascript.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.