dfowler Posted January 31, 2008 Share Posted January 31, 2008 Hey guys, I have some AJAX from a tutorial on this site that works perfectly with Firefox, but doesn't work AT ALL with IE. I was hoping somebody can take a look and see if I am missing something. AJAX Function - header.php <script type="text/javascript"> function ajaxFunction(ID, Param) { var loaderphp = "<?php echo $_SERVER['PHP_SELF'] ?>"; //test browsers var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch(e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { alert("Your browser does not support AJAX!"); return false; } } } xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { document.getElementById(ID).innerHTML = xmlHttp.responseText; } } xmlHttp.open("GET", loaderphp+"?Param="+Param,true); xmlHttp.send(null); } </script> Form - 1.php <?php include 'header.php'; //FIRST list box $query = "select * from table_a where active='1'"; $list1 = array(); $result=mysql_query($query); while (($row = mysql_fetch_assoc($result)) !== false) { $list1[] = $row; } if(isset($_GET['Param']) ) { $NewData = ""; $P = $_GET['Param']; if (!mysql_query("SELECT * FROM table_b WHERE a_id='$P'")) { echo "Database is down"; } $query = "select * from table_b where active='1' and a_id='$P'"; $result = mysql_query($query); while (($row = mysql_fetch_assoc($result)) !== false) { $NewData .= "<option value='".$row['id']."'>".$row['name']."</option>\n"; } echo $NewData; //Send Data back exit; } ?> <form method="post" enctype="multipart/form-data" name="myForm" target="_self" action="2.php"> <table border="0"> <tr> <td>Option A:<select name="list1" onChange="ajaxFunction('LBox2', this.value);"> <option value=''></option> <?php foreach($list1 as $l) { ?> <option value="<?php echo $l['id']; ?>"><?php echo $l['name']; ?></option> <?php } ?> </select> </td> <td>Option B:<select name="list2" id="LBox2"> </select> </td> </tr> </table> <input type="submit" name="Submit" value="Submit" /> </form> <?php include 'footer.php'; ?> Just to clarify, the form loads up on IE, but when you pick an option in the first select box nothing happens to the second select box. Quote Link to comment Share on other sites More sharing options...
dfowler Posted January 31, 2008 Author Share Posted January 31, 2008 I found another tutorial and just scrapped the old code. It now works on both IE and Firefox. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.