function iosajaxobj() { var xo; if(window.XMLHttpRequest){ xo = new XMLHttpRequest(); } else if (window.ActiveXObject){ xo=new ActiveXObject("Msxml2.XMLHTTP"); if (!xo) { xo=new ActiveXObject("Microsoft.XMLHTTP"); } } return xo;}var ioshttp = iosajaxobj();function iosajaxquery() { var rnd = Math.random(); try { ioshttp.open('POST', 'index2.php'); ioshttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); ioshttp.setRequestHeader('charset', 'utf-8'); ioshttp.onreadystatechange = function () { if (ioshttp.readyState == 4) { if (ioshttp.status!=200) { alert('Error, please retry'); } else { alert(ioshttp.responseText); } } }; ioshttp.send('option=com_test&task=mytask&id=xx&rnd='+rnd); } catch(e){} finally{}}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><style type="text/css">body{ background-repeat:no-repeat; font-family: Trebuchet MS, Lucida Sans Unicode, Arial, sans-serif; height:100%; background-color: #FFF; margin:0px; padding:0px;}select{ width:150px;}</style><script type="text/javascript">var ajax = new Array();function getCategoryList(sel){ var section_id = sel.options[sel.selectedIndex].value; // Το κλειδί section_id στον πίνακα categories document.getElementById('category').options.length = 0; // Άδειασμα του select box categories if(section_id.length>0){ var index = ajax.length; ajax[index] = new sack(); ajax[index].requestFile = 'getCategory.php?section_id='+section_id; // Επιλογή σε ποιό αρχείο να πάει. ajax[index].onCompletion = function(){ createTmima(index) }; // Επιλέγει ποια function θα εκτελεσθεί όταν βρεί το αρχείο ajax[index].runAJAX(); // Εκτελεί την AJAX function }}function createCategory(index){ var obj = document.getElementById('category'); eval(ajax[index].response); // Executing the response from Ajax as Javascript code }</script>
<body><?phprequire 'config.php';?><form action="" method="post"><table> <tr> <td colspan="2"><b>Section - Category Select example</b></td> </tr> <tr> <td>Section: </td> <td><?php $link = mysql_connect($dbhost, $dbuser, $dbpass); $query="SELECT * FROM categories"; $result = mysql_query ($query); echo "<select id="Section" name="Section" onchange="getCategoryList(this)"; echo "<option value='-1'>Select a Section</option>\n"; while($row=@mysql_fetch_array($result, MYSQL_BOTH)) { if($row['Section_id']==$data['Section_id']) $SELECTED="SELECTED"; else $SELECTED=""; echo "<option value='".$row['Section_id']."' $SELECTED>".$row['Section']."</option>\n"; } echo "</select>"; // Closing of list box ?> </td> </tr> <tr> <td>Category: </td> <td><select id="category" name="category"> </select> </td> </tr></table></form></body></html>
<?phpif(isset($_GET['category'])){ switch($_GET['category']){ case "1": echo "obj.options[obj.options.length] = new Option('VW','1');\n"; echo "obj.options[obj.options.length] = new Option('BMW','2');\n"; echo "obj.options[obj.options.length] = new Option('AUDI','3');\n"; echo "obj.options[obj.options.length] = new Option('OPEL','4');\n"; break; case "2": echo "obj.options[obj.options.length] = new Option('Βάρκα','11');\n"; echo "obj.options[obj.options.length] = new Option('Ταχύπλοο','12');\n"; echo "obj.options[obj.options.length] = new Option('Θαλαμηγός','13');\n"; break; case "3": echo "obj.options[obj.options.length] = new Option('Boing','21');\n"; echo "obj.options[obj.options.length] = new Option('Airbus','22');\n"; break; } }?>