<html> <head> <script type = text/javascript src = getschool1.js></script> <link rel="stylesheet" type="text/css" href="form.css"> </head> <body> <form id = 'prices' action="process.php" method="post"> <table> <td align="right">Language of interest:</td> <td> <select id="language" name="language" onChange="getSchool1(this.value)"> <option value="none selected"> --- select --- </option> <option value="french">French</option> <option value="german">German</option> <option value="italian">Italian</option> <option value="spanish">Spanish</option> <option value="russian">Russian</option> </select> </td> <tr> <td align="right">School</td> <td> <select id="school" name ="school" onChange="getAge(this.value)"disabled> <option value="none selected">Select Language First</option> </select> </td> </tr> <tr> <td align="right">Course Type</td> <td> <select id = "age" name="age" onChange="getLevel(this.value)" disabled> <option value="none selected"> Select School First </option> </select> </td> </tr> <tr> <td align="right">Class Type</td> <td> <select id="level" name="level" onChange="getDuration(this.value)" disabled> <option value="none selected">Select Course Type First</option> </select> </td> </tr> <tr> <td align="right">Duration</td> <td> <select id="duration" name="duration" onChange="getPlace(this.value)" disabled> <option value="none selected">Select Class Type First</option> </select> </td> </tr> <tr> <td align="right">Accommodation</td> <td> <select id ="place" name ="place" onChange = "getBoard(this.value)" disabled> <option value="none selected">Select Duration First</option> </tr> <tr> <td align="right">Board</td> <td> <select id ="board" name="board" onChange = "getRoom(this.value)" disabled> <option value="none selected">Select Acc First</option> </tr> <td align="right">Room Type</td> <td> <select id ="room" name="room" onChange = "getSeason(this.value)" disabled> <option value="none selected">Select Board First</option> </tr> <tr> <td align="right">Season</td> <td> <select id ="season" name="season" disabled> <option value="none selected">Select Room First</option> </tr> </br> <td align="right">Currency</td> <td> <select name="currency" > <option value="none selected"> --- select --- </option> <option value="euro">Euro</option> <option value="sterling">Sterling</option> <option value="dollar">Dollar</option> </tr> <tr> <td> <input type="submit" id="submit" name="submit" value="Submit" /> <input type="hidden" name="submitted" id="submitted" value="true" /> </tr> </td> </table>
function GetXmlHttpObject(){ var xmlHttp = false; try{ xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")//For Old Microsoft Browsers } catch(e){ try{ xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")//For Microsoft IE 6.0+ } catch(e2){ xmlHttp = false; } } if (!xmlHttp && typeof XMLHttpRequest != 'undefined') { xmlHttp = new XMLHttpRequest();//For Mozilla, Opera Browsers } if(!xmlHttp) { alert("Browser does not support HTTP Request"); } return xmlHttp; } function getSchool1(langID){ var xmlhttp = GetXmlHttpObject(); if(!xmlhttp){ return; } var url = "findcity.php" + "?language=" + langID + "&sid=" + Math.random(); xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState == 4){ document.getElementById("school").innerHTML = xmlhttp.responseText; document.getElementById("school").disabled = 0; } }; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function getAge(school){ var xmlhttp = GetXmlHttpObject(); if(!xmlhttp){ return; } var langID = document.getElementById("language").value; //var school = document.getElementById("school").value; var url = "findage.php" + "?language=" + langID + "&school="+ school + "&sid=" + Math.random(); xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState == 4){ document.getElementById("age").innerHTML = xmlhttp.responseText; document.getElementById("age").disabled = 0; } }; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function getLevel(age){ var xmlhttp = GetXmlHttpObject(); if(!xmlhttp){ return; } var langID = document.getElementById("language").value; var schoolID = document.getElementById("school").value; var url = "findlevel.php" + "?language=" + langID + "&school="+ schoolID + "&age="+ age + "&sid=" + Math.random(); alert(url); xmlhttp.onreadystatechange = function(){ if (xmlhttp.readyState == 4){ document.getElementById("level").innerHTML = xmlhttp.responseText; document.getElementById("level").disabled = 0; } }; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function getDuration(level){ var xmlhttp = GetXmlHttpObject(); if(!xmlhttp){ return; } var langID = document.getElementById("language").value; var schoolID = document.getElementById("school").value; var ageID = document.getElementById("age").value; var url = "getduration.php" + "?language=" + langID + "&school=" + schoolID + "&age="+ ageID + "&level=" + level + "&sid=" + Math.random(); alert(url); xmlhttp.onreadystatechange = function(){ if (xmlhttp.readyState == 4){ // document.getElementById("durationdiv").innerHTML = xmlhttp.responseText; document.getElementById("duration").innerHTML = xmlhttp.responseText; document.getElementById("duration").disabled = 0; alert(xmlhttp.responseText); } }; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function getPlace(duration){ var xmlhttp = GetXmlHttpObject(); if(!xmlhttp){ return; } var langID = document.getElementById("language").value; var schoolID = document.getElementById("school").value; var ageID = document.getElementById("age").value; var levelID = document.getElementById("level").value; var url = "findplace.php" + "?language=" + langID + "&school=" + schoolID + "&age="+ ageID + "&level=" + levelID + "&duration=" + duration + "&sid=" + Math.random(); xmlhttp.onreadystatechange = function(){ if (xmlhttp.readyState == 4){ // document.getElementById("durationdiv").innerHTML = xmlhttp.responseText; document.getElementById("place").innerHTML = xmlhttp.responseText; document.getElementById("place").disabled = 0; } }; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function getBoard(place){ var xmlhttp = GetXmlHttpObject(); if(!xmlhttp){ return; } var langID = document.getElementById("language").value; var schoolID = document.getElementById("school").value; var ageID = document.getElementById("age").value; var levelID = document.getElementById("level").value; var durationID = document.getElementById("duration").value; var url = "findboard.php" + "?language=" + langID + "&school=" + schoolID + "&age="+ ageID + "&level=" + levelID + "&duration=" + durationID + "&place=" + place + "&sid=" + Math.random(); xmlhttp.onreadystatechange = function(){ if (xmlhttp.readyState == 4){ // document.getElementById("durationdiv").innerHTML = xmlhttp.responseText; document.getElementById("board").innerHTML = xmlhttp.responseText; document.getElementById("board").disabled = 0; } }; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function getRoom(board){ var xmlhttp = GetXmlHttpObject(); if(!xmlhttp){ return; } var langID = document.getElementById("language").value; var schoolID = document.getElementById("school").value; var ageID = document.getElementById("age").value; var levelID = document.getElementById("level").value; var durationID = document.getElementById("duration").value; var placeID = document.getElementById("place").value; var url = "findroom.php" + "?language=" + langID + "&school=" + schoolID + "&age="+ ageID + "&level=" + levelID + "&duration=" + durationID + "&place=" + placeID + "&board=" + board + "&sid=" + Math.random(); xmlhttp.onreadystatechange = function(){ if (xmlhttp.readyState == 4){ // document.getElementById("durationdiv").innerHTML = xmlhttp.responseText; document.getElementById("room").innerHTML = xmlhttp.responseText; document.getElementById("room").disabled = 0; } }; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function getSeason(room){ var xmlhttp = GetXmlHttpObject(); if(!xmlhttp){ return; } var langID = document.getElementById("language").value; var schoolID = document.getElementById("school").value; var ageID = document.getElementById("age").value; var levelID = document.getElementById("level").value; var durationID = document.getElementById("duration").value; var placeID = document.getElementById("place").value; var boardID = document.getElementById("board").value; var url = "findseason.php" + "?language=" + langID + "&school=" + schoolID + "&age="+ ageID + "&level=" + levelID + "&duration=" + durationID + "&place=" + placeID + "&board=" + boardID + "&room=" + room + "&sid=" + Math.random(); xmlhttp.onreadystatechange = function(){ if (xmlhttp.readyState == 4){ // document.getElementById("durationdiv").innerHTML = xmlhttp.responseText; document.getElementById("season").innerHTML = xmlhttp.responseText; document.getElementById("season").disabled = 0; } }; xmlhttp.open("GET",url,true); xmlhttp.send(null); }
<?php $language = $_GET["language"]; $school = $_GET["school"]; $age = $_GET["age"]; mysql_connect("localhost", "root", "filabo01") or die(mysql_error()); mysql_select_db("burkes1_jos") or die(mysql_error()); $query = mysql_query("SELECT le.leveltype FROM ssa_level AS le, ssa_schoolid AS s, ssa_course AS c, ssa_age as ag WHERE s.school = '$school' AND ag.agetype = '$age' AND s.schoolid = c.schoolid AND ag.ageid = c.ageid AND le.levelid = c.levelid GROUP BY le.leveltype") or die (mysql_error()); ?> <option>Select Class Type</option> <? while($row = mysql_fetch_array($query)) { ?> <option value = <?=$row['leveltype']?>><?=$row['leveltype']?></option> <? } ?>
document.getElementById("room").disabled = 0;
document.getElementById("room").setAttribute('disabled', 0);
<select ....></select> tags (including all attributes, id , name , onchange - but not disabled ).
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Airshow :: Untitled</title> <!-- daniweb_post959826.html --> <link rel="stylesheet" type="text/css" href="form.css"> <script type = text/javascript src = getschool1.js></script> <script> function GetXmlHttpObject(){ var xmlHttp = false; try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP") //For Old Microsoft Browsers } catch(e){ try{ xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")//For Microsoft IE 6.0+ } catch(e2){ xmlHttp = false; } } if (!xmlHttp && typeof XMLHttpRequest != 'undefined'){ xmlHttp = new XMLHttpRequest();//For Mozilla, Opera Browsers } if(!xmlHttp) { alert("Browser does not support HTTP Request"); } return xmlHttp; } //********************************************************************* function getNextMenu(x){ var xmlhttp = GetXmlHttpObject(); if(!xmlhttp){ return; } var menus = [ [ 'language' , 'findcity.php' ], [ 'school' , 'findage.php' ], [ 'age' , 'findlevel.php' ], [ 'level' , 'findduration.php' ], [ 'duration' , 'findplace.php' ], [ 'place' , 'findboard.php' ], [ 'board' , 'findroom.php' ], [ 'room' , 'findseason.php' ], [ 'season' , '' ] ]; //1. Compose url - we can now do this by looping through the menus array. var queryString = []; for(var i=0; i<menus.length; i++){ var menu = document.getElementById(menus[i][0]); if(menu && !menu.getAttribute('disabled')){ queryString.push(menu.name + '=' + menu[menu.selectedIndex].value); } } url = menus[x][1] + '?' + queryString.join('&'); //2. Establish AJAX response handler xmlhttp.onreadystatechange = function(){ var menu, menuContainer, cloned; if (xmlhttp.readyState == 4){ //2a. Set options for next menu in the cascade. menu = document.getElementById(menus[x+1][0]); if(menu){ menuContainer = menu.parentNode; if(!menuContainer.getAttribute('cloned')){ menuContainer.nullClone = menu.cloneNode(true);//clone the "null" menu and stash it away (invisibly) as an attribute of the menu's container. menuContainer.setAttribute('cloned', 1); } menuContainer.innerHTML = xmlhttp.responseText; } //2b. User may go back, higher in the cascade, and se-select from a menu. // This will invalidate all subordinate menus in the cascade. // Therefore reset all subordinate menus to "null" settings. for(var i=x+2; i<menus.length; i++){ menu = document.getElementById(menus[i][0]); if(menu){ menuContainer = menu.parentNode; if(menuContainer && menuContainer.getAttribute('cloned')){ menuContainer.replaceChild(menuContainer.nullClone.cloneNode(true), menu); } } } } }; xmlhttp.open("GET",url,true); xmlhttp.send(null); } </script> </head> <body> <form id='prices' action="process.php" method="post"> <table> <td align="right"> Language of interest:</td> <td> <select id="language" name="language" onChange="getNextMenu(0)"> <option value="none selected"> --- select --- </option> <option value="french"> French</option> <option value="german"> German</option> <option value="italian"> Italian</option> <option value="spanish"> Spanish</option> <option value="russian"> Russian</option> </select> </td> <tr> <td align="right"> School</td> <td> <select id="school" name="school" onChange="getNextMenu(1)" disabled> <option value="none selected"> Select Language First</option> </select> </td> </tr> <tr> <td align="right"> Course Type</td> <td> <select id="age" name="age" onChange="getNextMenu(2)" disabled> <option value="none selected"> Select School First </option> </select> </td> </tr> <tr> <td align="right"> Class Type</td> <td> <select id="level" name="level" onChange="getNextMenu(3)" disabled> <option value="none selected"> Select Course Type First</option> </select> </td> </tr> <tr> <td align="right"> Duration</td> <td> <select id="duration" name="duration" onChange="getNextMenu(4)" disabled> <option value="none selected"> Select Class Type First</option> </select> </td> </tr> <tr> <td align="right"> Accommodation</td> <td> <select id="place" name="place" onChange="getNextMenu(5)" disabled> <option value="none selected"> Select Duration First</option> </select> </td> </tr> <tr> <td align="right"> Board</td> <td> <select id="board" name="board" onChange="getNextMenu(6)" disabled> <option value="none selected"> Select Acc First</option> </select> </td> </tr> <tr> <td align="right"> Room Type</td> <td> <select id="room" name="room" onChange="getNextMenu(7)" disabled> <option value="none selected"> Select Board First</option> </select> </tr> <tr> <td align="right"> Season</td> <td> <select id="season" name="season" disabled> <option value="none selected"> Select Room First</option> </select> </td> </tr> <tr> <td align="right"> Currency</td> <td> <select name="currency" > <option value="none selected"> --- select --- </option> <option value="euro"> Euro</option> <option value="sterling"> Sterling</option> <option value="dollar"> Dollar</option> </select> </td> </tr> <tr> <td> <input type="submit" id="submit" name="submit" value="Submit" /> <input type="hidden" name="submitted" id="submitted" value="true" /> </td> </tr> </td> </table> </body> </html>
getNextMenu() , (eg. at the bottom of the querystring composition loop) then re-enable it in the onreadystatechange response handler. (In fact it might be a good idea to disable the whole cascade).
<html> <head> <title>Roshan's Ajax dropdown code</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <? #### Roshan's Ajax dropdown code with php #### Copyright reserved to Roshan Bhattarai - nepaliboy007@yahoo.com #### if you have any problem contact me at http://roshanbh.com.np #### fell free to visit my blog http://php-ajax-guru.blogspot.com ?> <script> function GetXmlHttpObject(){ var xmlHttp = false; try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP") //For Old Microsoft Browsers } catch(e){ try{ xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")//For Microsoft IE 6.0+ } catch(e2){ xmlHttp = false; } } if (!xmlHttp && typeof XMLHttpRequest != 'undefined'){ xmlHttp = new XMLHttpRequest();//For Mozilla, Opera Browsers } if(!xmlHttp) { alert("Browser does not support HTTP Request"); } return xmlHttp; } //********************************************************************* function getNextMenu(x){ var xmlhttp = GetXmlHttpObject(); if(!xmlhttp){ return; } var menus = [ [ 'country' , 'findcity.php' ], [ 'city' , 'findvalue.php' ], [ 'value' , '' ] ]; //1. Compose url - we can now do this by looping through the menus array. var queryString = []; for(var i=0; i<menus.length; i++){ var menu = document.getElementById(menus[i][0]); if(menu && !menu.getAttribute('disabled')){ queryString.push(menu.name + '=' + menu[menu.selectedIndex].value); } } url = menus[x][1] + '?' + queryString.join('&'); //2. Establish AJAX response handler xmlhttp.onreadystatechange = function(){ var menu, menuContainer, cloned; if (xmlhttp.readyState == 4){ //2a. Set options for next menu in the cascade. menu = document.getElementById(menus[x+1][0]); if(menu){ menuContainer = menu.parentNode; if(!menuContainer.getAttribute('cloned')){ menuContainer.nullClone = menu.cloneNode(true);//clone the "null" menu and stash it away (invisibly) as an attribute of the menu's container. menuContainer.setAttribute('cloned', 1); } menuContainer.innerHTML = xmlhttp.responseText; } //2b. User may go back, higher in the cascade, and se-select from a menu. // This will invalidate all subordinate menus in the cascade. // Therefore reset all subordinate menus to "null" settings. for(var i=x+2; i<menus.length; i++){ menu = document.getElementById(menus[i][0]); if(menu){ menuContainer = menu.parentNode; if(menuContainer && menuContainer.getAttribute('cloned')){ menuContainer.replaceChild(menuContainer.nullClone.cloneNode(true), menu); } } } } }; xmlhttp.open("GET",url,true); xmlhttp.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" id="country" onChange="getNextMenu(0)"> <option value="">Select Country</option> <option value="1">USA</option> <option value="2">Canada</option> </select></td> </tr> <tr style=""> <td>City</td> <td ><select name="city" id="city" onChange="getNextMenu(1)" disabled> <option value="none selected"> Select country First</option> </select></td> </tr> <tr style=""> <td>Value</td> <td > <select name="value" id="value" disabled> <option value="none selected"> Select city First </option> </select> </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> </tr> </table> </form> </body> </html>
<? $city=intval($_REQUEST['city']); $link = mysql_connect('localhost', 'root', ''); //changet the configuration in required if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db('db_ajax'); $query="select val from city where id=$city"; $result=mysql_query($query); $valrow=mysql_fetch_assoc($result); ?> <input type="text" name="value" value="<?php echo $valrow['val']; ?>">
| DaniWeb Message | |
| Cancel Changes | |