PHP
OOPs
JavaScript
JQuery
Ajax
Codeigniter
Laravel
MySql
Node.js
Tutorials
C
C++
Json
Codeigniter 4
htaccess
wordpress
react.js
Blogs
Fundamental
Python
Search Your Query
×
--- Select Category ---
PHP
OOPs
JavaScript
JQuery
Ajax
Codeigniter
Laravel
MySql
Node.js
Tutorials
Blogs
Fundamental
Python
Most Popular Tutorials
What is Javascript
BOM (Browser object model)
DOM (Document object model)
Variable
Variable is empty or Not
Javascript output
Function
Events
Array
Get text value
Get Form field value
Pattern validation
Form validation
Checkbox validation
Inner Html form validation
Form validation on php server
Window and window location
Get Text Value
get javascript value in php
Date Format
Get php variable in javascript
Redirect page in javascript
Auto Refresh page and DIV
Get text value from dropdown
Clear Browser History
Get Checkbox value
select (Dropdown)
PopUp Contact Form
sidebar contact form
Show modal on page load
Auto calculate price GST
print html and Div content
Calculate Discount prince
Checked single or all checkbox
Auto Fill form data on click checkbox
Show subcategory (Dependent Dropdown)
country, state, city (Dependent Dropdown)
Image upload with preview image
Filter table data
Character Limit Validation
uploading file size validation
Special Character validation
multiple file upload (Add more)
function call after page load
Disable Submit Button After Form Submission
disable browser back button
Remove selected item from second & third dropdown list
Interview Question
Active Tab Menu
String methods
Tutorials Menus
What is Javascript
BOM (Browser object model)
DOM (Document object model)
Variable
Variable is empty or Not
Javascript output
Function
Events
Array
Get text value
Get Form field value
Pattern validation
Form validation
Checkbox validation
Inner Html form validation
Form validation on php server
Window and window location
Get Text Value
get javascript value in php
Date Format
Get php variable in javascript
Redirect page in javascript
Auto Refresh page and DIV
Get text value from dropdown
Clear Browser History
Get Checkbox value
select (Dropdown)
PopUp Contact Form
sidebar contact form
Show modal on page load
Auto calculate price GST
print html and Div content
Calculate Discount prince
Checked single or all checkbox
Auto Fill form data on click checkbox
Show subcategory (Dependent Dropdown)
country, state, city (Dependent Dropdown)
Image upload with preview image
Filter table data
Character Limit Validation
uploading file size validation
Special Character validation
multiple file upload (Add more)
function call after page load
Disable Submit Button After Form Submission
disable browser back button
Remove selected item from second & third dropdown list
Interview Question
Active Tab Menu
String methods
Share On Facebook
How to show dynamic dependent dropdown using javascript?
Show city list state wise in dropdown select box using Javascript.
File name : index.php
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
var citiesByState = {
Odisha: ["Bhubaneswar","Puri","Cuttack"],
Maharashtra: ["Mumbai","Pune","Nagpur"],
Kerala: ["kochi","Kanpur"]
}
function makeSubmenu(value) {
if(value.length==0) document.getElementById("citySelect").innerHTML = "<option></option>";
else {
var citiesOptions = "";
for(cityId in citiesByState[value]) {
citiesOptions+="<option>"+citiesByState[value][cityId]+"</option>";
}
document.getElementById("citySelect").innerHTML = citiesOptions;
}
}
function displaySelected() { var country = document.getElementById("countrySelect").value;
var city = document.getElementById("citySelect").value;
alert(country+"\n"+city);
}
function resetSelection() {
document.getElementById("countrySelect").selectedIndex = 0;
document.getElementById("citySelect").selectedIndex = 0;
}
</script>
</head>
<body onload="resetSelection()">
<select id="countrySelect" size="1" onchange="makeSubmenu(this.value)">
<option value="" disabled selected>Choose State</option>
<option>Odisha</option>
<option>Maharashtra</option>
<option>Kerala</option>
</select>
<select id="citySelect" size="1" >
<option value="" disabled selected>Choose City</option>
<option></option>
</select>
<button onclick="displaySelected()">show selected</button>
</body>
</html>
Output :-
Choose State
Bihar
Odisha
Maharashtra
Kerala
Choose City
show selected
Show district list as per country and state select in dropdown select box Javascript
File name : index.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script>
var stateObject = {
"India": { "Delhi": ["new Delhi", "North Delhi"],
"Kerala": ["Thiruvananthapuram", "Palakkad"],
"Goa": ["North Goa", "South Goa"],
},
"Australia": {
"South Australia": ["Dunstan", "Mitchell"],
"Victoria": ["Altona", "Euroa"]
}, "Canada": {
"Alberta": ["Acadia", "Bighorn"],
"Columbia": ["Washington", ""]
},
}
window.onload = function () {
var countySel = document.getElementById("countySel"),
stateSel = document.getElementById("stateSel"),
districtSel = document.getElementById("districtSel");
for (var country in stateObject) {
countySel.options[countySel.options.length] = new Option(country, country);
}
countySel.onchange = function () {
stateSel.length = 1; // remove all options bar first
districtSel.length = 1; // remove all options bar first
if (this.selectedIndex < 1) return; // done
for (var state in stateObject[this.value]) {
stateSel.options[stateSel.options.length] = new Option(state, state);
}
}
countySel.onchange(); // reset in case page is reloaded
stateSel.onchange = function () {
districtSel.length = 1; // remove all options bar first
if (this.selectedIndex < 1) return; // done
var district = stateObject[countySel.value][this.value];
for (var i = 0; i < district.length; i++) {
districtSel.options[districtSel.options.length] = new Option(district[i], district[i]);
}
}
}
</script>
</head>
<body>
<form name="myform" id="myForm">
Select Country: <select name="state" id="countySel" size="1">
<option value="" selected="selected">Select Country</option>
</select>
<br>
<br>
Select State: <select name="countrya" id="stateSel" size="1">
<option value="" selected="selected">Please select Country first</option>
</select>
<br>
<br>
Select District: <select name="district" id="districtSel" size="1">
<option value="" selected="selected">Please select State first</option>
</select><br>
<input type="submit">
</form>
</body>
</html>
Output :-
Untitled Document
Select Country:
Select Country
Select State:
Please select Country first
Select District:
Please select State first
Share On Facebook
Previous
Next
Trending Tutorials
PHP
100+ Tutorials
PHP OOPs
80+ Tutorial
Codeigniter
100+ Tutorial
Laravel
100+ Tutorials
NODE.JS
100+ Tutorials
Javascript
100+ Tutorials
Download Live Projects
Review & Rating
0.0
/ 5
0
Review
5
(
0
)
4
(
0
)
3
(
0
)
2
(
0
)
1
(
0
)
Write Review Here
Review
Submit Review
×
Submit
Ittutorial
Ittutorial
Most Popular Tutorials
Events
BOM (Browser object model)
country, state, city (Dependent Dropdown)
Calculate Discount prince
Array
Redirect page in javascript
Filter table data
Javascript output
Variable is empty or Not
Form validation
Get text value from dropdown
Character Limit Validation
Active Tab Menu
Inner Html form validation
disable browser back button
Clear Browser History
Function
print html and Div content
Get Text Value
What is Javascript
Important Link
Core php Online Advance Tutorails and video Tutorials.
How to manage Session in php Tutorials.
More .......
upcomming codeigniter and angular js tutorials.
Click here to see More ...
Hello Friend Please Follow & Share Ittutorial.
×
Ittutorial
Please Follow and Share ittutorial.
Ittutorial