Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>Ajax dropdown code</title>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
- <script>
- function getXMLHTTP() { //fuction to return the xml http object
- var xmlhttp=false;
- try{
- xmlhttp=new XMLHttpRequest();
- }
- catch(e) {
- try{
- xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
- }
- catch(e){
- try{
- xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
- }
- catch(e1){
- xmlhttp=false;
- }
- }
- }
- return xmlhttp;
- }
- function getCity(strURL) {
- var req = getXMLHTTP();
- if (req) {
- req.onreadystatechange = function() {
- if (req.readyState == 4) {
- // only if "OK"
- if (req.status == 200) {
- document.getElementById('citydiv').innerHTML=req.responseText;
- } else {
- alert("There was a problem while using XMLHTTP:\n" + req.statusText);
- }
- }
- }
- req.open("GET", strURL, true);
- req.send(null);
- }
- }
- function getCountry(strURL) {
- var req = getXMLHTTP();
- if (req) {
- req.onreadystatechange = function() {
- if (req.readyState == 4) {
- // only if "OK"
- if (req.status == 200) {
- document.getElementById('countrydiv').innerHTML=req.responseText;
- } else {
- alert("There was a problem while using XMLHTTP:\n" + req.statusText);
- }
- }
- }
- req.open("GET", strURL, true);
- req.send(null);
- }
- }
- </script>
- </head>
- <body>
- <form method="post" action="" name="form1">
- <table width="60%" border="0" cellspacing="0" cellpadding="0">
- <tr>
- <td width="150">Country</td>
- <td width="150"><select name="country" onChange="getCity('findcity.php?country='+this.value)">
- <option value="">Select Country</option>
- <option value="1">USA</option>
- <option value="2">Canada</option>
- </select></td>
- </tr>
- <tr style="">
- <td>City</td>
- <td ><div id="citydiv"><select name="city" onChange="getCountry('findcountry.php?city='+this.value)">
- <option>Select City</option>
- </select></div></td>
- </tr>
- <td>Country</td>
- <td ><div id="countrydiv"><select name="country2">
- <option>Select Country</option>
- </select></div></td>
- </tr>
- <tr>
- <td> </td>
- <td> </td>
- </tr>
- <tr>
- <td> </td>
- <td> </td>
- </tr>
- </table>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement