By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,516 Members | 1,153 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,516 IT Pros & Developers. It's quick & easy.

How do i make an "onChange" event to register in internet explorer?

P: 5
Hi all, i am writing an ajax and php application for a sec ondary school, and i want the contents of one select list to be based on the values of the select list that appears before it. The issue is that the onChange event that fires the function that sends the ajax request to populate the second select list does not have any effect when i am using internet explorer. Please help me fix this.
I have enclosed my code below.
Tanx.
This is the form that accepts data
Expand|Select|Wrap|Line Numbers
  1. <?php session_start();?>
  2. <html>
  3. <head>
  4. <link rel="stylesheet" type="text/css" href="main2.css">
  5. <script type="text/javascript">
  6.  var request = false;
  7.    try {
  8.      request = new XMLHttpRequest();
  9.    } catch (e) {
  10.      try {
  11.        request = new ActiveXObject("Msxml2.XMLHTTP");
  12.      } catch (e2) {
  13.        try {
  14.          request = new ActiveXObject("Microsoft.XMLHTTP");
  15.        } catch (e3) {
  16.          request = false;
  17.        }  
  18.      }
  19.    }
  20.    if (!request)
  21.      alert("Sorry Your Browser Settings Do Not Permit You To Use This Application!");
  22.      var request2 = false;
  23.    try {
  24.      request2 = new XMLHttpRequest();
  25.    } catch (e) {
  26.      try {
  27.        request2 = new ActiveXObject("Msxml2.XMLHTTP");
  28.      } catch (e2) {
  29.        try {
  30.          request2 = new ActiveXObject("Microsoft.XMLHTTP");
  31.        } catch (e3) {
  32.          request = false;
  33.        }  
  34.      }
  35.    }
  36.    if (!request2)
  37.      alert("Sorry Your Browser Settings Do Not Permit You To Use This Application!");
  38. function get_number(){
  39. var i=document.getElementById("number").value;
  40. var class=document.getElementById("get_class").value;
  41. var form=document.getElementById("form").value;
  42. if (i=="")
  43. {alert("Please Supply A Valid Number");
  44. return;}
  45.    if(form==0){
  46.    alert("Please Select A Valid Form!!! ");
  47.    return;}
  48. else{ var url = "/demonstration/get_number.php?number=" + escape(i) + "&class=" +escape(class)+"&form=" +escape(form);
  49.      request2.open("GET", url, true);
  50.      request2.onreadystatechange = updatePage;
  51.      request2.send(null);}
  52.  
  53.    }
  54.       function updatePage(){
  55. if(request2.readyState==4){
  56. if(request2.status==200)
  57. {var response2=request2.responseText;
  58. if (request2.responseText=='')
  59. {alert("Sorry,An Error Ocurred.Please Try Again Later.!!");}
  60. else{
  61.  
  62. document.getElementById("feedback").innerHTML=response2;
  63.  
  64.  
  65. }
  66.  
  67. }
  68. else{
  69. alert("Status is " + request.status);}}}
  70. function getclass(){
  71. var i=document.getElementById("number").value;
  72. var form=document.getElementById("form").value;
  73.  
  74.    if(form==0){
  75.    alert("Please Select A Valid Form!!! ");}
  76.    else{
  77.    var url = "/demonstration/get_class.php?form=" + escape(form);
  78.      request.open("GET", url, true);
  79.      request.onreadystatechange = updateForm;
  80.      request.send(null);}}
  81.      function updateForm(){
  82. if(request.readyState==4){
  83. if(request.status==200)
  84. {var response=request.responseText.split("|");
  85. if (request.responseText=='')
  86. {alert("Sorry,An Error Ocurred.Please Try Again Later.!!");}
  87. else{
  88.  
  89. document.getElementById("get_class").innerHTML=response[0];
  90.  
  91.  
  92. }
  93.  
  94. }
  95. else{
  96. alert("Status is " + request.status);}}}
  97.  
  98.  
  99. </script>
  100. </head>
  101.  
  102. <body>
  103. <div class="container" align="center">
  104. <h2 align="center">Please Enter The Form,Class And Number Of Fresh Students You Want To Register Below</h2>
  105. <hr/>
  106. <?php 
  107. $user_id=$_SESSION['user_id'];
  108. include 'demo_connect.php';
  109.  
  110. $sql="select * from forms";
  111. $result=mysqli_query($link,$sql);
  112.  
  113. echo '
  114. <table><tr><td class=form align=right>Form:</td><td><select name="form" id=form onChange=getclass();>
  115. <option value=0>Select Form Here</option>';
  116. while ($r=mysqli_fetch_assoc($result))
  117. {$form=$r['form_name'];
  118.  
  119. echo "<option value="; echo $r['form_id'];echo ">$form\n";
  120. }
  121. echo'</select></td></tr>
  122. <tr><td class=form align=right>Class:</td><td id="class_feedback"><select id=get_class><option value=0>Get Class here</select></td></tr>
  123.  
  124. <tr><td class="form" align=right>Enter Desired Number Here:<td><input type="text" id="number"></td><td></td><td><input type="button" value="Submit Number" onClick="get_number();"></td></tr></table>
  125. <div id=feedback></div>
  126. <div id=submit_form></div>';
  127. ?>
  128.  
  129.  
  130. </div>
  131. </body>
  132. </html> 
AND THIS IS THE PHP FORM THAT RECEIVES THE AJAX REQUEST
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>Untitled Document</title>
  6. </head>
  7.  
  8. <body>
  9. <?php
  10. include 'demo_connect.php';
  11. $form_id=mysqli_real_escape_string($link,$_GET['form']);
  12. $sql="select * from classes where form_id='$form_id' order by class_name";
  13. $result=mysqli_query($link,$sql);
  14. $a='
  15. <select name="class" id="class" onChange=trial();>
  16.  
  17.  
  18. ';
  19. while ($r=mysqli_fetch_assoc($result))
  20. {$class=$r['class_name'];
  21.  
  22. echo "<option value=";echo $r['class_id'];echo">$class\n</option>";
  23. }
  24. echo'</select></td></tr>';
  25. echo $a;
  26.  
  27. ?>
  28. </body>
  29. </html>
  30.  
Mar 30 '11 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.