Ajax Talk - Asynchronous javascript and xml discussion board
 FAQ   Search    Usergroups      Register   Profile   Check your messages   Log in 
Signup now to enjoy a range of free membership advantages !!
Ajax Talk - Moderators Wanted
Probem with Country/State Dropdown Menu

 
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> AJAX general discussion
View previous topic :: View next topic  
Author Message
bub255
New one
New one


Joined: 16 Nov 2007
Posts: 1

PostPosted: Fri Nov 16, 2007 11:18 am    Post subject: Probem with Country/State Dropdown Menu Reply with quote

I'm new to AJAX, this is my first AJAX script...
I named the topic Country/State because the concept is similar, but I used Province/Town instead...
I got it work on Mozilla Firefox and Opera Browsers, but it didn't work on IE...
My IE Browser version is capable with AJAX and HTTP requests...
Was it on my AJAX code?

Any help please?
Thanks in advance!

Here's all the file involved:

>> index.php
Code:

<html>
<head>
<title>AJAX Province/Town Selector</title>
<script language="javascript">
var xmlHttp

function loadTowns(str) {
   xmlHttp=GetXmlHttpObject()
   if (xmlHttp==null) {
      alert ("Browser does not support HTTP Request")
      return
   }
   var url="townloader.php"

   url=url+"?prov="+str
   url=url+"&sid="+Math.random()
   xmlHttp.onreadystatechange=stateChanged
   xmlHttp.open("GET",url,true)
   xmlHttp.send(null)
}

function stateChanged() {
   if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
      document.getElementById("town").innerHTML=xmlHttp.responseText
   }
}

function GetXmlHttpObject() {
   var xmlHttp=null;
   try {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
   } catch (e) {
      //Internet Explorer
      try {
         xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
   }
   return xmlHttp;
}
</script>
</head>
<body>
<form name="frm" method="post" action="submit.php">
<pre>Province : <select name="prov" onChange="loadTowns(this.value)">
               <option value="0">-- Select Province --</option>
                    <option value="1">Province 1</option>
                    <option value="2">Province 2</option>
                    <option value="3">Province 3</option>
            </select>

Town :     <select name="town" id="town">
            <option value="0">-- Select Town --</option>
         </select>

           <input type="submit" /></pre>
</form>
</body>
</html>


>> townloader.php
Code:

<?php
$prov=$_GET["prov"];

echo "<option value='0'>-- All Towns --</option>\n";

switch ($prov) {
case 0:
   break;
case 1:
   for($Ptr = 1;$Ptr < 6;$Ptr++) echo "<option value='" .$Ptr. "'>" . "Province 1's Town " .$Ptr. "</option>\n";
   break;
case 2:
   for($Ptr = 1;$Ptr < 6;$Ptr++) echo "<option value='" .$Ptr. "'>" . "Province 2's Town " .$Ptr. "</option>\n";
   break;
case 3:
   for($Ptr = 1;$Ptr < 6;$Ptr++) echo "<option value='" .$Ptr. "'>" . "Province 3's Town " .$Ptr. "</option>\n";
   break;
}
?>


>> and the submit.php
Code:

<html>
<head>
<title>AJAX Country/State</title>
</head>
Province : <?php echo $_POST['prov']; ?><br />
Town : <?php echo $_POST['town']; ?><br />
<body>
</body>
</html>
Back to top
View user's profile Send private message
Jesdisciple
Frequent Poster
Frequent Poster


Joined: 20 Oct 2007
Posts: 36
Location: Tejas

PostPosted: Mon Nov 19, 2007 4:30 am    Post subject: Reply with quote

The following index.php shows that the data is received by the browser, so I'm thinking it must be a problem with IE's implementation of innerHTML. Try using add() (http://w3schools.com/htmldom/dom_obj_select.asp).
Code:
<html>
   <head>
      <title>AJAX Province/Town Selector</title>
      <script language="javascript">
      var xmlHttp
      
      function loadTowns(str) {
         xmlHttp=GetXmlHttpObject()
         if (xmlHttp==null) {
           alert ("Browser does not support HTTP Request")
           return
         }
         var url="townloader.php"
      
         url=url+"?prov="+str
         url=url+"&sid="+Math.random()
         xmlHttp.onreadystatechange=stateChanged
         xmlHttp.open("GET",url,true)
         xmlHttp.send(null)
      }
      
      function stateChanged() {
         if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
           document.getElementById("town").innerHTML=xmlHttp.responseText
alert(document.getElementById("town").innerHTML);
         }
      }
      
      function GetXmlHttpObject() {
         var xmlHttp=null;
         try {
           // Firefox, Opera 8.0+, Safari
           xmlHttp=new XMLHttpRequest();
         } catch (e) {
           //Internet Explorer
           try {
             xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
           } catch (e) {
             xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
           }
         }
         return xmlHttp;
      }
      </script>
   </head>
   <body>
      <form name="frm" method="post" action="submit.php">
         <pre>
            Province :
            <select name="prov" onChange="loadTowns(this.value)">
               <option value="0">-- Select Province --</option>
               <option value="1">Province 1</option>
               <option value="2">Province 2</option>
               <option value="3">Province 3</option>
            </select>
         
            Town :
            <select name="town" id="town">
               <option value="0">-- Select Town --</option>
            </select>
         
            <input type="submit" />
         </pre>
      </form>
   </body>
</html>

_________________
In ALL things, strive for ><>,
Chris
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> AJAX general discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
 Advertisements
 XML & Copyright Notice 
    


Powered by phpBB © 2001, 2005 phpBB Group

What is according to Wikipedia: Ajax Web2.0 XML E4X


Link to our site:

  


del.icio.us digg spurl wists simpy newsvine blinklist furl blogmarks yahoo! myweb smarking ma.gnolia segnalo reddit fark technorati cosmos


Normal Bookmark


Partner Button Links:
Codecrunch.com: Webmaster Tutorials    One Ajax


Partner Text Links:
quomon | web20log | ajaxmatters | tableless | 456bereastreet | music charts | gift ideas | competitions | free xbox 360 | link trade ?


Credits:
it consultancy & project management lead generation zoekmachine optimalisatie steal these buttons seo expert