-
Get Country and State dropdown dynamically in PHP
We can use country and state dropdown dynamically in php using javascript. Here, You can derived it by follows the below easy steps :
Let’s get started:
Step 1 : Download the countries3.js file from this link : http://sourceforge.net/projects/countries/files/.
Step 2 : Put below code in HTML file
View Code PHP1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Country/State Select Demo</title> <style type="text/css"> body{font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#333;} input {width: 140px; margin-right: 5px; padding: 3px; border: 1px solid #DFE1E0;} </style><script type="text/javascript" src ="countries-2.0-min.js"></script> </head> <body onload = "alert('JavaScripts Loading completed! Now check the demonstration...');"> <div align ="center"> <h1>Free JavaScript Country/State Selection Demo</h1> <hr><br> Select Country: <select onchange="print_state('state',this.selectedIndex);" id="country" name ="country"></select> <br /> City/District/State: <select name ="state" id ="state"></select> <script language="javascript">print_country("country");</script> <script type="text/javascript">date_populate("date", "month", "year");</script> <br><br> </div> </body> </html>
Now, run your file as created in above steps, by that you will found dynamic Country and state dropdown.